Event.DEACTIVATE event fired automatically?

Shawn's Avatar

Shawn

20 Sep, 2010 09:00 PM

I ran into a bit of a confusing issue, and was wondering if I could get some clarification.

I needed to setup a command which fired in response to the NativeApplication.DEACTIVE event, so I mapped the command like so:
commandMap.mapEvent(Event.DEACTIVATE, SaveCommand);

To my surprise, the SaveCommand was now fired without me needing to dispatch it manually... this confuses me as I would assume I need to dispatch this event using the eventDispatcher before it would be picked up by the framework.

I've had to do this for other "root" events, for example, Event.RESIZE coming from the stage does not get automatically picked up.

Why is this? And, is there a list of these auto-dispatched events that we can look at?

  1. 1 Posted by Stray on 20 Sep, 2010 09:26 PM

    Stray's Avatar

    If it bubbles to the context then I would assume this is the source of your firing?

  2. 2 Posted by Shawn Blais on 20 Sep, 2010 10:19 PM

    Shawn Blais's Avatar

    Hmm, that doesn't really make sense though, since NativeApplication is the
    root element of the app, it really shouldn't be bubbling anywhere...

    My contextView is not the app itself, it's a <group> embedded in the
    main.mxml file.

    On Mon, Sep 20, 2010 at 3:28 PM, Stray <
    [email blocked]<tender%[email blocked]>
    > wrote:

  3. 3 Posted by Stray on 20 Sep, 2010 10:26 PM

    Stray's Avatar

    Ah, ok, after a little digging in the API docs for Event.DEACTIVATE, it turns out that it doesn't bubble, instead it is broadcast:

    Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. This event is a broadcast event, which means that it is dispatched by all EventDispatcher objects with a listener registered for this event. For more information about broadcast events, see the DisplayObject class.

    So - I think it's just the fact that it's a broadcast event that means that the shared event dispatcher is firing it anyway, and you don't need to listen for it and pass it on.

  4. 4 Posted by Shawn Blais on 21 Sep, 2010 01:46 AM

    Shawn Blais's Avatar

    Nice, learned something new. Thanks for clearing that up :)

  5. Support Staff 5 Posted by Shaun Smith on 21 Sep, 2010 10:49 AM

    Shaun Smith's Avatar

    Interesting stuff - was unaware of "broadcast events" myself.

  6. 6 Posted by Shawn Blais on 21 Sep, 2010 04:10 PM

    Shawn Blais's Avatar

    Ya weird stuff. To receive DEACTIVATE anywhere in my app you can just do this:
    var d:EventDispatcher = new EventDispatcher();
    d.addEventListener(Event.DEACTIVATE, onDeactivated);

    And it works. Funky...

    Seems to be limited to just ACTIVATE and DEACTIVATE right now btw.

  7. Stray closed this discussion on 12 Feb, 2011 11:04 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac