RE: [flexcoders] Re: Broadcasting event to all objects on display list

2008-02-14 Thread Alex Harui
If each node must be responsible for the dispatch to its children, then
yes, you're probably doing it the right way.  It'll chew up some cycles,
but all tree walks effectively do.  The only way to optimize is to
flatten the tree at some point which breaks the abstraction you want.

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of thirtyfivemph
Sent: Thursday, February 14, 2008 8:17 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Broadcasting event to all objects on display
list

 

Actually, I'm trying to avoid each DisplayObject tracing its way back
to the root (which, at any given time, it may not be able to do
depending on where it is in the DisplayList, on or off the stage, etc.).

Here's a more succinct way to ask my question:

Given that the display list is a classic tree (one parent, many
children), is there any mechanism that is natural and efficient
within Flash's existing event architecture that would allow me to
dispatch an event from a parent DisplayObject and have that event
propagate down the tree through children, grandchildren, etc.?

Currently, I only see this as the most compact solution:

Each DisplayObject listens for the ADDED and REMOVED events. When
these events occur, the DisplayObject adds a listener to its parent
for the desired custom event. In the listener, the DisplayObject
redispatches the event so that any of its children who are listening
can receive it, and they then do the same thing. Thus, if I ever call
myDisplayObject.dispatchEvent() all of myDisplayObject's children,
grandchildren, great-grandchildren, etc. will eventually receive the
event, without anyone having to know anything more than their parent
and children.

Basically, it's propagating events like messages through a network
topology: each node figures out how to broadcast to the next node, no
one node has to know about all of the other nodes, just its immediate
neighbors.

If my solution above sounds like the best route, and it sounds
reasonably efficient (my real concern), I'll probably just create a
new base class for all my objects that implements this.

Troy.

 



Re: [flexcoders] Re: Broadcasting event to all objects on display list

2008-02-14 Thread Troy Gilbert
 If each node must be responsible for the dispatch to its children, then yes,
 you're probably doing it the right way.  It'll chew up some cycles, but all
 tree walks effectively do.  The only way to optimize is to flatten the
 tree at some point which breaks the abstraction you want.

Cool. The tree's not too deep (A - B - C - D - E), and virtually
all of the elements are in the leafs, so most of the dispatching
should be in the native event system with very little in my
redispatching code.

Troy.


RE: [flexcoders] Re: Broadcasting event to all objects on display list

2008-02-14 Thread Gordon Smith
It would be unnatural to try to use the event mechanism to propogate an
event to all descendants of a tree node. Use a recursive method call to
accomplish this.
 
Gordon Smith
Adobe Flex SDK Team



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of thirtyfivemph
Sent: Thursday, February 14, 2008 8:17 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Broadcasting event to all objects on display
list



Actually, I'm trying to avoid each DisplayObject tracing its way back
to the root (which, at any given time, it may not be able to do
depending on where it is in the DisplayList, on or off the stage, etc.).

Here's a more succinct way to ask my question:

Given that the display list is a classic tree (one parent, many
children), is there any mechanism that is natural and efficient
within Flash's existing event architecture that would allow me to
dispatch an event from a parent DisplayObject and have that event
propagate down the tree through children, grandchildren, etc.?

Currently, I only see this as the most compact solution:

Each DisplayObject listens for the ADDED and REMOVED events. When
these events occur, the DisplayObject adds a listener to its parent
for the desired custom event. In the listener, the DisplayObject
redispatches the event so that any of its children who are listening
can receive it, and they then do the same thing. Thus, if I ever call
myDisplayObject.dispatchEvent() all of myDisplayObject's children,
grandchildren, great-grandchildren, etc. will eventually receive the
event, without anyone having to know anything more than their parent
and children.

Basically, it's propagating events like messages through a network
topology: each node figures out how to broadcast to the next node, no
one node has to know about all of the other nodes, just its immediate
neighbors.

If my solution above sounds like the best route, and it sounds
reasonably efficient (my real concern), I'll probably just create a
new base class for all my objects that implements this.

Troy.



 


Re: [flexcoders] Re: Broadcasting event to all objects on display list

2008-02-14 Thread Troy Gilbert
 It would be unnatural to try to use the event mechanism to propogate an
 event to all descendants of a tree node. Use a recursive method call to
 accomplish this.

So, you're thinking something like this (pseudo-code):

for (var i:int = 0; i  this.numChildren; i++)
{
var child:IPropogatableDisplayObject = this.getChildAt(i) as
IPropogatableDisplayObject;
if (child) child.handleEvent(myCustomEvent);
}

Something like that? I guess that would be more efficient... Of
course, the nice thing about the event system is that it already had a
priority system and default cancelling, which are behaviors that I
need as well.

Once I rolled that functionality in, do you think this approach would
still be significantly more efficient than hijacking the event system?
Depth of my tree is 5 to 6 levels, total number of nodes is less than
100, number of events (per node) would be about 10 per frame.

Troy.


RE: [flexcoders] Re: Broadcasting event to all objects on display list

2008-02-14 Thread Gordon Smith
With that few nodes, efficiency probably isn't an important
consideration.
 
Gordon Smith
Adobe Flex SDK Team



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Troy Gilbert
Sent: Thursday, February 14, 2008 2:56 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: Broadcasting event to all objects on
display list



 It would be unnatural to try to use the event mechanism to propogate
an
 event to all descendants of a tree node. Use a recursive method call
to
 accomplish this.

So, you're thinking something like this (pseudo-code):

for (var i:int = 0; i  this.numChildren; i++)
{
var child:IPropogatableDisplayObject = this.getChildAt(i) as
IPropogatableDisplayObject;
if (child) child.handleEvent(myCustomEvent);
}

Something like that? I guess that would be more efficient... Of
course, the nice thing about the event system is that it already had a
priority system and default cancelling, which are behaviors that I
need as well.

Once I rolled that functionality in, do you think this approach would
still be significantly more efficient than hijacking the event system?
Depth of my tree is 5 to 6 levels, total number of nodes is less than
100, number of events (per node) would be about 10 per frame.

Troy.