0

I'm currently porting a Flash game to OUYA (an Android powered device) via Adobe AIR.

Most of the work has been done already; it's packaged up and runs on Android devices.

However! When I double-tap the middle button to return to the system home screen (which I believe to be the equivalent of pressing the home button on an Android mobile), the app doesn't seem to pause or exit, and the music can still be heard.

Does anyone have any tips on how to suspend or exit an AIR app when the home button is pushed? Thanks!

Bob
  • 55
  • 1
  • 9

2 Answers2

2

Try listening for Event.DEACTIVATE. That dispatches when Flash/AIR loses focus in the context of the operating system/browser. Should be exactly what you are looking for. You should attach it to NativeApplication.nativeApplication, I believe. Attaching it to the Stage might also work, but I'm not entirely sure.

If you want to listen for the app to exit, listen for Event.EXITING on NativeApplication.

Josh
  • 8,079
  • 3
  • 24
  • 49
  • For mobile applications I am pretty confident they have to be added through NativeApplication.nativeApplication. Up-vote for explaining how to handle background mode in AIR. – Nabren Oct 15 '13 at 20:09
0

I ended up doing this:

this.stage.addEventListener(flash.events.Event.ACTIVATE, onResume, false, 0, true);
this.stage.addEventListener(flash.events.Event.DEACTIVATE, onPause, false, 0, true);

In my init, and then:

    private function onPause(event:flash.events.Event):void
    {
      SoundMixer.stopAll();
    }

    private function onResume(event:flash.events.Event):void
    {
      FP.world = new MenuWorld();
    }
Bob
  • 55
  • 1
  • 9