5 Replies Latest reply on Jun 14, 2011 5:19 AM by relaxatraja

    Android/AIR Show last screen you left off when re-opened?

    GP Animations

      I made a little trivia game that loads questions from an xml file. The problem is, if you leave the app and come back to it, it starts you back at the start screen again. Is there anyway to overwrite this, or is it the same as refreshing a browser page with a Flash animation on it, it'll always keep restarting? Thanks in advance!

        • 1. Re: Android/AIR Show last screen you left off when re-opened?
          relaxatraja Level 5

           

          import flash.desktop.NativeApplication;

           

          import flash.desktop.SystemIdleMode;

          if (Capabilities.cpuArchitecture == "ARM") //Optional condition{

          NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);

          }

          private function handleActivate(event:Event):void {

          NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

          }

          • 2. Re: Android/AIR Show last screen you left off when re-opened?
            GP Animations Level 1

            I have something like that already. I believe the problem is because I'm loading external .swfs as well.


            Master .swf file keeps screen on and loads an external .swf:


            import flash.events.Event;
            import flash.net.URLRequest;
            import flash.display.Loader;
            import flash.events.ProgressEvent;
            import flash.desktop.NativeApplication;

             

            //Keep screen on during app
            NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;


            //Make sure screen can go to sleep upon exiting
            var application:NativeApplication = NativeApplication.nativeApplication;
            application.addEventListener(Event.EXITING, onExit);
            function onExit (e:Event): void {
                application.removeEventListener(Event.EXITING, onExit);
                application.systemIdleMode = SystemIdleMode.NORMAL;
            }

             

            //Quit Actions
            if(Capabilities.cpuArchitecture=="ARM"){
                NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
                NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
                NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
            }
            function handleActivate(event:Event):void {
                NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
            }
            function handleDeactivate(event:Event):void {
                NativeApplication.nativeApplication.exit();
            }
            function handleKeys(event:KeyboardEvent):void {
                if(event.keyCode == Keyboard.BACK) {
                    NativeApplication.nativeApplication.exit();
                }
            }

             

            //Buttons load external .swf files
            startBtn.addEventListener(MouseEvent.CLICK, gotoMenu);
            function gotoMenu(e:Event): void {
                 var loadMenu:Loader = new Loader();
                 var menuURL:URLRequest=new URLRequest("ENA.swf");
                 loadMenu.contentLoaderInfo.addEventListener(Event.COMPLETE, menuDone);
                 loadMenu.load(menuURL);
                 function menuDone(loadEvent:Event) {
                     addChild(loadEvent.currentTarget.content);
                     startBtn.removeEventListener(MouseEvent.CLICK, gotoMenu);
                 }
            }

             

             

            ENA.swf

             

            if(Capabilities.cpuArchitecture=="ARM"){
                NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
                NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
                NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
            }
            function handleActivate(event:Event):void {
                NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
            }
            function handleDeactivate(event:Event):void {
                NativeApplication.nativeApplication.exit();
            }
            function handleKeys(event:KeyboardEvent):void {
                if(event.keyCode == Keyboard.BACK) {
                    NativeApplication.nativeApplication.exit();
                }
            }

             

             

             

            I believe the problem is in the exam .swfs because they're a mixture of .as, .xml and .swf files and give the error: 1120 access of undefined property Capabilities If I use the code you've provided.

            • 3. Re: Android/AIR Show last screen you left off when re-opened?
              relaxatraja Level 5

              Just use the code in your main file, why loading the ena.swf again for the same functionality?

              • 4. Re: Android/AIR Show last screen you left off when re-opened?
                GP Animations Level 1

                The main file is a preloader/title screen shell that loads an information page/main menu .swf.

                 

                The main menu swf leads to 9 different quizzes that are externally loaded.

                 

                Each quiz is a mixture of .as, .xml, and .swf.

                 

                The KEEP_AWAKE code works in the main file and menu .fla timeline. However, in the quiz .fla timelines it gives an undefined error. My only guess is because there is an external .as file messing up the .fla timeline code, but I'm not sure why.