iosactionscript-3airevent-listenernativeapplication

Event.ACTIVATE on `this` or on NativeApplication?


I'm building an AIR-based iOS app as pure AS3 from FlashBuilder, and I want to detect ACTIVATE and DEACTIVATE events when the app loses focus.

Much of the docs say to register the event listener against NativeApplication.nativeApplication, but I'm just registering it against this, in the context of the application's Main class. And it works.

Is there any risk to doing it that way? What are the reasons for explicitly using the NativeApplication singleton instance to register event listeners?


Solution

  • The main SWF (this) receives the ACTIVATE and DEACTIVATE events through bubbling. If it's easier to just write the event listener against this, then do it that way. So far I haven't seen any downside to it, and it works really well at detecting loss of app focus. At least on iOS.