Flex 3: bubbling event propagation

I found this simple example in this forum:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Flex/Q_23869684.html

I want to use it to apply the use of the bubbling event propagation.  I am trying to understand it better and want to apply this to the simple example.  Can someone modify the example to demonstrate the use of a bubbled event?

LVL 4
newbiealAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IkluCommented:
I can do a pretty good example in flash cs4 and actionscript 3.0 if you want it.
0
newbiealAuthor Commented:
Although I'm working with Flex and AS 3.0, your example might help, thanks.
0
zzynxSoftware engineerCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

newbiealAuthor Commented:
Yes, I've seen that one and I understand that the event propagates however how is this useful?  I was trying to apply it to a smaller app so that I could understand the benefit of bubbling propagation.
0
zzynxSoftware engineerCommented:
It's about the order you want events to be processed.

Condition:
Assume that you want this processing order:
1) VBox should process the event
2) Afterwards Application should process the event (because what you want to do in the Application part depends on the fact that VBox already processed the event)

You can capture the event in the Application part in the "Capturing Phase" and in the "Bubbling Phase".
But with the above condition, you have no choice as processing the event in Application in the "Bubbling Phase".

I hope that is clear to you.

0
newbiealAuthor Commented:
zzynx,

thank you, but I'm still foggy on this.  If I have several display controls, what is the likelihood that every display control needs to know about an event that fired somewhere else?  Would it not be more efficient to implement some logic, let's say if button fired in panel A, that only Panel X that needs to know about it should know about the event?  Wny bubble up events through all the display controls when they not all need to know about it?  It seems to be a lot of overhead.  I only know about this propagation type from reading and have looked at demos and understand how it works, but still do not understand it usefulness.  I also found it interesting that the bubbling event propagates only with the controls that explicitly call the addEventListener...shouldn't it at least bubble up automatically?

thanks!
0
zzynxSoftware engineerCommented:
>> shouldn't it at least bubble up automatically?
Events will by default not bubble!
In order to have an event bubble, you need to create it with an extra parameter set to "true".
The default constructor of event is:
Event(type:String, bubbles:Boolean=false, cancellable:Boolean=false)

>> I also found it interesting that the bubbling event propagates only with the controls that explicitly call the addEventListener.
If the event bubbles up (see above) only the controls that listen to it (via addEventListener) get triggered

>> ... understand how it works, but still do not understand it usefulness.
Then you'll probably not gonna need it for your application ;o)
The normal way of "catching" events is in the Propagation Phase.
I gave you a theoretical example of its usefulness.
0
IkluCommented:
Event bubbling can be very useful in some applications.  I created an application for managing accounts for a game.  The user has different forms that he or she has to complete.  I have a Main class that manages each screen in an event listener that listens for a custom event I created called DoneEvent.  Each screen added is a class that dispatches a DoneEvent whenever the screen has done everything it is supposed to do.

When the event is dispatched, the listener in the Main class can be triggered in the capture phase, and if I have a listener in the screen object, it is triggered in the target phase.

With bubbling the Main event listener is triggered after the event listener in the screen object which is more useful because I generally have the listener in the screen object removing itself.
0
newbiealAuthor Commented:
Iklu, thanks for the example.  That make sense to make use of the bubbling event in your case, but couldn't all of this be done the regular way of event handling...what I'm trying to figure out is if making use of this type of propagation is more efficient in terms of memory?
0
zzynxSoftware engineerCommented:
>> ... but couldn't all of this be done the regular way of event handling
You mean propagation

>> what I'm trying to figure out is if making use of this type of propagation
You mean bubbling
>> is more efficient in terms of memory?
What makes you think bubbling would be less memory efficient than propagation?

0
newbiealAuthor Commented:
I thought bubbling is a propagation type? No?
0
zzynxSoftware engineerCommented:
Yes it is.

What do you mean with "the regular way of event handling" and "this type of propagation"?
0
tludewigCommented:
I have a few total noob questions.

1.  How can i trace and print out each currentTarget value as the event bubbles up from the target?
2.  How is it possible that in actionscript for my custom component, i.e., MyList which extends an HBox, sometimes, trace(parent.name); prints out an object and other times, throws an exception b/c the parent is null?  In one method in MyList, the parent gets printed out just fine and in another method, it is null.  I thought the parent of MyList would always be HBox, no?  I am obviously very confused.  And it makes determining the event bubbling chain quite difficult since i cannot even figure out what the target's ancestors are.
0
IkluCommented:
HBox is the superclass of MyList.  MyList has to be added as a child to something valid for parent to allow access to the parent.
0
zzynxSoftware engineerCommented:
>> I have a few total noob questions.
And you're asking them in a question of newbieal?
Why not posting your own?
Or are "tludewig" and "newbieal" both accounts of you?
0
tludewigCommented:
Sorry...didn't mean to add to someone else's post.  Didn't realize that's bad protocol.
0
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.