dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] What does "bubbles" mean?

  1. #1
    Member
    Join Date
    Sep 2009
    Posts
    88

    resolved [RESOLVED] What does "bubbles" mean?

    I was coding an event dispatcher which wasn't working (I needed to listen to the event from another class). Then after some search, came across a post with 5tons saying something about bubbling so figured I would add a parameter (true) to the dispatched event to try and see if it would work, it did.

    From livedocs:
    Determines whether the Event object participates in the bubbling stage of the event flow.

    Couldn't find more info about that bubble stuff and the livedocs definition isn't very clear.

    Is "to bubble" meaning to make it global and that's all there is to it?

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    no , bubbles means that if set to true , the event will continue to propagate all the way up through the inheritance tree, rather than just the immediate parent.

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    To clarify, "inheritance tree" in this case refers to the display list and not class inheritance

  4. #4
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    my fault. i didn't think about the duality of inheritance. note, setting bubbles to true does not mean all things in the display list , receive this event. Only direct ascendants of the child. bubbling does not transfer events laterally.

  5. #5
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,131
    Well, the thing that added the listener always gets the event; even if it's not on the display chain at all. Only the currentTarget changes. So something about these explanations is funny.

    My understanding was that bubbling was only relevant for MouseEvents, to allow further propagation up the display chain; my sense was -- and I could be wrong about this -- that any object placing a listener on another object always receives the event at capture, except for mouse listeners placed on parent objects, which will only receive the event if it bubbles beyond the parent. I never thought it had anything to do with non-mouse events dispatched by an EventDispatcher at all.

  6. #6
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    bubbling is not only relevant for mouse events.

    Object A extends UIComponent
    contains objects of type
    B extends UIComponent , that are placed in a container sprite , called 'holder'.

    class a registers for an event at the class level ,
    Code:
    addEventListener( "testEvent" , onTestEvent );
    with corresponding event handler :

    Code:
    private function onTestEvent( evt : Event ) : void {
           trace( "on test event" );
    };
    on creationComplete object of class b , dispatches a custom event :

    Code:
    dispatchEvent( new Event( "testEvent" , false , false ) );
    this will not work. because bubbling is set to false.

    This would work if i said :

    Code:
    holder.addEventListener( "testEvent" , this.onTestEvent );

    or it would work if i did this :

    Code:
    dispatchEvent( new Event( "testEvent" , true, false ) );

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center