1
votes

I have a flex application, the display of this application is build with many containers. I have a FlexEvent.UPDATE_COMPLETE on each of the displayObjects.

What do I want to accomplish? I want to handle the event only on the top level where it occurred, for instance, if I have a grid and the update occurred in a label somewhere inside, I want to handle the event only on the Grid.

is there a way to accomplish that?

just to emphasize, I don't have any knowledge of the display objects at compile time, only at runtime, the display is being built dynamically to I can't just write the code on the grid, I have to check somehow if the event occurred in a higher level.

I would love some help with this issue, even if it's not code but concept of how to handle this unique issue.

Thanks

2

2 Answers

0
votes

Have you considered stopPropagation()/stopImmediatePropagation() on the event, once you handle that event.

Example: Since your button is in canvas. Your event handler method in canvas would look like this,

function handleEvent(e:FlexEvent):void {
 trace("In Canvas's handler");
 //do your events...
 e.stopPropagation(); //This stops from propagating e to its parent containers, which is an HBOX. The container can be anything at runtime, it doesnt affect the propagation.

}

Try the same example in your other containers too.

Some examples here,

http://livedocs.adobe.com/flex/3/html/help.html?content=events_08.html

http://livedocs.adobe.com/flex/3/langref/flash/events/Event.html#stopPropagation%28%29

0
votes

Just check for the event.target and ignore if it is not what you're looking for. Or even better: listen for events on top level components and ignore if target and currentTarget doesn't match.

if(event.target != event.currentTarget) 
    return;

If you can't do this either, check the parents: if parent is your application or the container that holds the top level items, it is a top level item. Based on the structure of your component, it can be anything like

if(event.target.parent == this)
//or
if(event.target.parent == this.theContainer_thatHolds_topLevelItems)
//or 
if(event.target.parent is Application)
//or 
if(event.target.parent is CustomContainerClassName)