Skip to main content
Known Participant
Jul 10, 2021 10:02 PM UTC
Answered

idle mode sceensaver time out for android app intrractive

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 is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    Jul 14, 2021 1:49 AM UTC

    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

    12 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    Jul 14, 2021 1:49 AM UTC

    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

    Translate
    oro1985Author
    Known Participant
    Jul 14, 2021 2:54 PM UTC

    Thanks JC!!

     

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

     

    thanks !!!!

     

    o

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Jul 14, 2021 4:38 PM UTC

    That's awesome! You're welcome!

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Jul 13, 2021 7:02 PM UTC

    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

    Translate
    oro1985Author
    Known Participant
    Jul 13, 2021 8:07 PM UTC

    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

     

    Translate
    Legend
    Jul 11, 2021 12:29 AM UTC

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

     

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

    Translate
    oro1985Author
    Known Participant
    Jul 11, 2021 10:27 PM UTC

    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.

     

     

    Translate
    Legend
    Jul 11, 2021 11:45 PM UTC

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

    Translate