How to create timeout for touchscreen kiosk programmed Flash

cavemantoyboy
cavemantoyboy used Ask the Experts™
on
Hi,

I have created a simple touch screen kiosk in flash that will be used to access food recipes.  

Users click through a series of menus and sub-menus to narrow down their search to a few recipes in their preferred area.  Theses menus are separated into scenes with buttons linking back and forth between these scenes.

I need a script that will take the flash back to the home screen after 90 seconds if nothing is pressed.  This will allow a new user to jump into the program from the beginning and not where the last person left it.

Solutions very much valued and appreciated. Cheers.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009

Commented:
See code snippet. The timer class is not exactly accurate but it should be fine for your software, if you want the 90 seconds to be really accurate, consider getTimer() or Date Class.

var nothingispressed:Boolean = true; // make sure you add nothingispressed = true when some button is pressed.
var timer:Timer = new Timer(90000, 1);
timer.addEventListener(TimerEvent.TIMER, updateTime);
timer.start();
 
function updateTime(e:TimerEvent):void
{
        if(nothingispressed) {
		// now jump back to beginning, add your own code.
	}
}

Open in new window

Author

Commented:
Hi, I just copied and pasted the code into the first frame of the flash file.  Nothing happened.  What am I supposed to add to the code.  I'm very new at actionscipt so perhaps you can fill it in with an example and I'll replace it with the correct "Names".  Am I supposed to copy this script to the beginning of all scenes, or just the first scene the swf starts on?
Don't worry guys I found some help from the webpage http://the-dude.co.uk/tutorials/flash-as2-tutorials/countdown-timer-for-flash-games-as2/ and I have a solution now.
//First off we need to set the default for our timer, the value it will count down from.
timer = 90;
//Next we need to create the function that will control the countdown:
countdown = function(){
timer--;
//Simply, the lines of code abouve create a function called countdown, and when this function is run it will remove 1 from the total number of the timer variable.
//The problem with this is that even after the timer reaches 0, it is going to continue counting into the minuses. We need to add the following if statement into the function:
if(timer==0){
clearInterval(countdownInterval);
gotoAndPlay("Screensaver", 1);
 
}
}
//This is basically saying if the timer is equal to 0, clear the interval called countdownInterval. 
//Lastly, we need to create a 1 second interval to run the function, therefore removing one digit every second
countdownInterval = setInterval(countdown,1000);
//This declares a new interval called countdownTimer, and sets it to fun the function called countdown at an interval of 1000 milliseconds (equivilent to 1 second).

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial