A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AS3|AIR Understanding Event Propogation. Totally confused.

  1. #1
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378

    AS3|AIR Understanding Event Propogation. Totally confused.

    Here's the layout of my classes (as DisplayObjects on the Stage, it follows the same structure):

    The FLA
    Document Class
    Database :: Sprite
    Client :: Sprite
    Login Form :: Sprite

    The idea here is that I can have several Clients on the screen, and only one Database. When, for instance, the Database processes a login request, I believe there is no way for the Client to hear that event fire off as they're at the same depth in the DisplayObject hierarchy (correct me on this if I'm wrong; it's my first question).

    Secondly, from within the Client class I cannot seem to add an event listener to it that can hear the events fire from the Login Form class. Instead the Client has to add them to the Document's stage (aka the FLA stage), which in turn calls a function within the Client. I do not believe this to be good coding habits (ugly scope issues) and I don't believe this is right. I was under the impression that event propogation (with Bubbles = true) rode up the hierarchy to the Stage. Can someone elaborate on this? The "eventphase" doesn't really help me here, and I'd like if possible to be able to see the event go up the hierarchy (as I understand it, it also goes back down, too. Is this right?)

    To summarize:
    • Can two display objects at the same depth in the DisplayObject hierarchy hear each others events?
    • Can't a DisplayObject hear the events fired from its' children?
    • Does event propogation 'phases' mean the event goes up and then back down the hierarchy?


    Thanks to anyone who cares to help me out.

    *EDIT* It might also be important to note that the Client is actually extending NativeWindow, which I believe may be where some of my problems lie. In a worst-case scenario, if need be, I can make a central Event-handling class, but I was trying to avoid looping through the list of clients every time an event is dispatched. In this situation, I am also closing the 'root' Stage, and creating new NativeWindow (Clients) from a SystemTray object within the Document Class.
    Last edited by ImprisonedPride; 03-15-2012 at 12:03 PM. Reason: Clearing up stuff.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    To summarize:
    Can two display objects at the same depth in the DisplayObject hierarchy hear each others events?
    Can't a DisplayObject hear the events fired from its' children?
    Does event propogation 'phases' mean the event goes up and then back down the hierarchy?
    1) Yes. But only if they add the listeners to an object which either dispatches or is in the display ancestry. And the latter only if the event bubbles.
    For instance, if your client wanted to listen for the database dispatching an LOGIN_REQUEST event (which I'm making up), the code could go like this:
    Code:
    database.addEventListener(LoginEvent.LOGIN_REQUEST, client.doSomeLoginLogic);
    That or similar code could be done anywhere you have a reference to both the client and the database.

    2) Yes. But only if those events bubble.

    3) Backwards. The capture phase is when it goes down from stage to target, the bubble phase then happens, and goes back from target up to stage. Again, only if the event bubbles.

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