Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Flex 3: bubbling event propagation

Posted on 2009-07-13
17
Medium Priority
?
679 Views
Last Modified: 2013-11-11
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?

0
Comment
Question by:newbieal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
  • +1
17 Comments
 
LVL 2

Expert Comment

by:Iklu
ID: 24845350
I can do a pretty good example in flash cs4 and actionscript 3.0 if you want it.
0
 
LVL 4

Author Comment

by:newbieal
ID: 24845589
Although I'm working with Flex and AS 3.0, your example might help, thanks.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 1200 total points
ID: 24846943
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Author Comment

by:newbieal
ID: 24848950
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
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 1200 total points
ID: 24849136
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
 
LVL 4

Author Comment

by:newbieal
ID: 24849957
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
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 1200 total points
ID: 24850165
>> 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
 
LVL 2

Assisted Solution

by:Iklu
Iklu earned 300 total points
ID: 24873359
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
 
LVL 4

Author Comment

by:newbieal
ID: 24878730
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
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 1200 total points
ID: 24878957
>> ... 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
 
LVL 4

Author Comment

by:newbieal
ID: 24879128
I thought bubbling is a propagation type? No?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24879429
Yes it is.

What do you mean with "the regular way of event handling" and "this type of propagation"?
0
 

Expert Comment

by:tludewig
ID: 24937820
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
 
LVL 2

Expert Comment

by:Iklu
ID: 24941289
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
 
LVL 37

Expert Comment

by:zzynx
ID: 24949283
>> 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
 

Expert Comment

by:tludewig
ID: 24950397
Sorry...didn't mean to add to someone else's post.  Didn't realize that's bad protocol.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 25164420
Thanx 4 axxepting
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question