Skip to main content
Known Participant
July 10, 2021
Answered

idle mode sceensaver time out for android app intrractive

  • July 10, 2021
  • 3 replies
  • 1169 views

Hi, I'm building an interactive station. with different menus and videos. I have a startup screen that is a movieclip symbol with a video playing. I need help creating a timeout code to return the app to the initial state after 3 minutes of inactivity (no mouse movement or gestures).

will appreciatte any help.

 

thanks!

 

 

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    I'm not sure why.

     

    Animate isn't recognizing my device so I cannot debug the app.

     

    In this case let's go with the setTimeout approach. As an example, I have a very simple app that has two frames: the first one containing a start button and in the second one a timeout of 5 seconds is set and if the user doesn't touch the screen within 5 seconds the timeline returns to frame 1. The code is like this:

     

    Frame 1:

    import flash.events.MouseEvent;
    import flash.utils.clearTimeout;
    import flash.utils.setTimeout;
    
    var delay:uint = 5000;
    var timeout:uint = 0;
    
    function main():void
    {
    	stop();
    	startButton.addEventListener(MouseEvent.CLICK, start);
    	stage.addEventListener(MouseEvent.MOUSE_DOWN, wake);	
    }
    
    function start(e:MouseEvent):void
    {
    	gotoAndStop(2);
    }
    
    function wake(e:MouseEvent):void
    {
    	clearTimeout(timeout);
    	timeout = setTimeout(idle, delay);
    }
    
    function idle():void
    {
    	gotoAndStop(1);
    }
    
    main();

     

    Frame 2:

    wake(null);

     

    The FLA / source / code / files is in here:

    https://github.com/joao-cesar/adobe/tree/master/animate%20cc/as3/idle

     

    I hope it helps.

     

    Regards,

    JC

    3 replies

    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    July 14, 2021

    I'm not sure why.

     

    Animate isn't recognizing my device so I cannot debug the app.

     

    In this case let's go with the setTimeout approach. As an example, I have a very simple app that has two frames: the first one containing a start button and in the second one a timeout of 5 seconds is set and if the user doesn't touch the screen within 5 seconds the timeline returns to frame 1. The code is like this:

     

    Frame 1:

    import flash.events.MouseEvent;
    import flash.utils.clearTimeout;
    import flash.utils.setTimeout;
    
    var delay:uint = 5000;
    var timeout:uint = 0;
    
    function main():void
    {
    	stop();
    	startButton.addEventListener(MouseEvent.CLICK, start);
    	stage.addEventListener(MouseEvent.MOUSE_DOWN, wake);	
    }
    
    function start(e:MouseEvent):void
    {
    	gotoAndStop(2);
    }
    
    function wake(e:MouseEvent):void
    {
    	clearTimeout(timeout);
    	timeout = setTimeout(idle, delay);
    }
    
    function idle():void
    {
    	gotoAndStop(1);
    }
    
    main();

     

    Frame 2:

    wake(null);

     

    The FLA / source / code / files is in here:

    https://github.com/joao-cesar/adobe/tree/master/animate%20cc/as3/idle

     

    I hope it helps.

     

    Regards,

    JC

    oro1985Author
    Known Participant
    July 14, 2021

    Thanks JC!!

     

    this workd perfectly.  i adapted the code to my proyect and everything works fine.

     

    thanks !!!!

     

    o

    JoãoCésar17023019
    Community Expert
    July 14, 2021

    That's awesome! You're welcome!

    JoãoCésar17023019
    Community Expert
    July 13, 2021

    Hi.

     

    The NativeApplication class has some really useful methods to handle these kind of situations. Have you tried it? You could write something like this:

    import flash.desktop.NativeApplication;
    import flash.events.Event;
    
    function userIdleHandler(e:Event):void
    {
    	trace("back");
    	// your reset code here
    }
    
    NativeApplication.nativeApplication.idleThreshold = 180; // time in seconds
    NativeApplication.nativeApplication.addEventListener(Event.USER_IDLE, userIdleHandler);

     

    Please let us know if this works for you.

     

    Regards,

    JC

    oro1985Author
    Known Participant
    July 13, 2021

    Thanks JC!

     

    the code works perfectly when tested in animate (using air debug launcher(mobile))

     

    but when i publish APK and install on android the timeout doesnt work.

    could irt be a problem with the publish settings?

    thanks!

     

    o

     

    Brainiac
    July 11, 2021

    Do you're saying you want to set some sort of timeout?

     

    https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout

    oro1985Author
    Known Participant
    July 11, 2021

    yes, when the interactive app is incative for 3 minutes (no touch gestutre or mouse events) should go to initial state. or make a movieclip visible.

     

     

    Brainiac
    July 11, 2021

    Okay. You saw the link I posted... right?