PDA

View Full Version : How can I set a timer to looking for any user action?


notsotrickyricky
07-25-2008, 05:59 PM
I'm working on a kiosk, I have the program already created what I need now is to make it load the start screen after a certain amount of inactivity. So if someone walks away it will reset to a the start screen. The whole thing is done with flash AS2.0. I have never set up a timer before in flash, I know AS2.0 has a setInterval() and setTimeout(), ( I think ) but how to create a listener for them and use them together is driving me crazy! Any help would be most welcome!

I am so new at this I have to look up everything about listeners and still don't think I have a grip on that!

Edit: I should add that I have 4 swf files that load on lvl 0 when a user pushes the appropriate button on one of the swf's navbar. Since I have them all loading at the lowest lvl I'm guessing I'll have to add a listener to each swf? Not sure if that makes a difference?

LivestockTony
07-30-2008, 12:14 AM
I'm new to flash, and went straight to AS3. This is how I'd do it, though it probably isn't best practices (I'm still learning)

In your class definition, you add

private var InactivityCounter:int = 0;

Then with your frame counter, or wherever you need to strart worrying about the user being inactive-

var frametimer:new Timer(framerate);
frametimer.addEventListener(TimerEvent.Timer, OnTick);


The function OnTick, if it's a frame counter probably does other stuff and already exists, so we add the lines:

InactivityCounter++;
if (InactivityCounter > Threshold) TheFunctionWhichResetsTheStartScreen();

Threshold is your delay in milliseconds/framerate...

At this point, we'd get forced to the start screen whenever our program had been running longer than the threshold time, so in our event handlers we add a line

private function handlerFunction(e:SomeEvent):void{
...
InactivityCounter = 0;
...
}

That resets the inactivity counter to zero, giving the user Threshold amount of time before he gets forced to the start screen.

I don't know how different AS2 would be.
HTH,
-TF

notsotrickyricky
07-30-2008, 02:08 PM
Thanks for the help, I actually ran across someones code sniplet that gave me some ideas and got it to work. This is what it looked like when I got done messing with it.

var mouseListener:Object = new Object();
Mouse.addListener(mouseListener);
this.onEnterFrame = function() {
mouseListener.onMouseDown = function(){
clearInterval(intervalID);
intervalID = setInterval(updateTimer,600000);
}
mouseListener.onMouseMove = function() {
clearInterval(intervalID);
intervalID = setInterval(updateTimer,600000);
}
}
var intervalID:Number = setInterval(updateTimer, 600000);
function updateTimer():Void {
loadMovieNum("intro.swf",0);
}


this restarts the intro.swf every 10 minutes if there hasn't been a mouse event. This worked in AS2.0. I use AS2.0 instead of AS3.0 because as a beginner it seems I am limited by AS3.0? I keep running across stuff that say you can't do that in AS3.0 where as you can in AS2.0?

Thanks again for your time and post.