views:

119

answers:

1

In my app I currently have a popup menu implemented as a BorderContainer with a lot of buttons, textfields, date pickers, etc. PopUpManager handles its appearing and disappearing based on some UI events.

I'd like to be able to drag the container by clicking on any part of it minus all the components on it. In other words, when I click on buttons, text fields, etc. I'd like for them to respond as usual and for the container not be draggable.

I've tried this very simple implementation

_menu.addEventListener(MouseEvent.ROLL_OVER, toggleDragON);
_menu.addEventListener(MouseEvent.ROLL_OUT, toggleDragOFF);

private function mouseDown(event:MouseEvent):void 
{ 
    _menu.startDrag(); 
} 

private function mouseReleased(event:MouseEvent):void 
{ 
    _menu.stopDrag(); 
}

but this definitely doesn't do the trick, i.e. all components lead to dragging. I've tried to make sure that mouseEnabled and mouseChildren are true for all the components but this doesn't seem to make any difference.

I then came across this thread which makes a lot of sense, but I have a hard time believing that the best way for one to handle this is to handle all click events for each of the components on the popup. Is there an obviously simple way to do this that I'm missing?

thank you!

f

+2  A: 

How about checking the target property of the event to check if it equals your menu?

if (event.target == _menu) {
    _menu.startDrag();
}
Wade Mueller
Wade, thank you for your help. Unfortunately that doesn't seem to do the trick - now nothing moves anymore. I debugged the app with this code and it seems like currentTarget is of the right type, but if I sub event.target for event.currentTarget I get the exact same effect as before... sigh!
fred august
Wade's answer is correct, there's something else going wrong.
Sophistifunk
More often than not, `event.target` will not be the same as _menu: what if the entire visible area of the menu contain a background image or some other components like that? @Sophistifunk
Amarghosh
I will definitely try that.thank you!
fred august
Well, that's the point, isn't it? Most of the time it's not, which is why you check, and only take action when the drag takes place on the _menu. But if UIComponent is being used instead of a skin, then yes, you'd want to be listening for that.
Sophistifunk