-
timeout control
hi!!
I'm working at a projector file to be shown in a public show...
my clients asked if I can set the file so that it "reset" to the first page, in case there is nobody at the desk...
is there any way to do something like that..I imagine a sort of timeout control..checking hte time spent since last "action" (buttons)
any suggestions??
please excuse my poor english..I know I haven't been "clear"...
-
Lifetime Friend of Site Staff
You could probably do this a lot easier by watching for mouse movement, but here's a solution that will watch for any button presses and restart the movie if nobody presses a button for 2 seconds (the timeout value is easily changed).
Code:
_global.counter = 0; // how long have we been inactive?
_global.interval = 100; // check at 1/10th sec intervals
_global.timeout = 2000; // timeout & restart after 5 sec
// this function will be run every _global.interval msec
// to increase and test _global.counter, when the counter
// reaches _global.timeout the movie will be restarted
_global.restart = function() {
_global.counter += _global.interval;
if (_global.counter > _global.timeout) {
_global.counter = 0;
_root.gotoAndPlay(1);
}
}
// start the restart "watcher" function
id = setInterval(restart, _global.interval);
// reset the counter if any button is pressed
Button.prototype.onPress = function() {
// activity! user still alive
_global.counter = 0; // clear reset counter
}
-
thank you Northcode
by the way... as you suggested it would be easier checking the mouse (and actually since I read your reply this makes much more sense to me than what I intended to do...) how would it be the code for such control?? and the action would be attached on a movieclip or what else??
thank you very much!!
-
Lifetime Friend of Site Staff
I was thinking about this more after I posted it and you still need a way to check for timeouts independent of the events you're trying to watch for. So, it really doesn't matter what kind of events you're looking for, the only way to make this code simpler would be to put the code that checks for a timeout in an enter frame event (instead of using setInterval) so it was running all the time.
-
Hi... I know this is an old thread but I'm rediscovering Flash on the old software that I have.....
My actionscripting is sketchy at the best of times so I'm afraid I need a little help.
In my project I have an opening frame which has a button that takes you to the main menu that contains a number of buttons each of which load and unload a movieclip (within which there is a back and forward button).
What I want is, if a button hasn't been pressed for a minute I want the movie to timeout and go back to the opening frame.
I've inserted your code on the first frame of my project and adjusted the time accordingly. However when I test it, initially it appears to work but each time a button is pressed the timeout time is shortened until it barely registers a change and I'm stuck on the opening frame.
I've attempted to decipher the coding but can't see where the problem is. Plus I'm not quite sure what the:
id = setInterval(restart, _global.interval
refers to.
Any advice would be greatly appreciated.
Thanks
-
Lifetime Friend of Site Staff
The line you don't undersstand is likely causing the problem you're seeing
id = setInterval(restart, _global.interval)
restart is the function that setInterval will call (in this case _global.reset) and _global.interval is the frequency at which the function will be called.
Each time you go back to frame 1 and execute that code you'll be setting up another interval and eventually they'll be called so frequently and the counter will be incremented to fast that it will just keep jumping back to frame 1 (also making the problem worse).
What we need is some guard code around the setup to prevent it from being called more than once.
This should do the trick,
Code:
if (_global.initialized != true)
{
// prevent this code from executing again
_global.initialized = true;
_global.counter = 0; // how long have we been inactive?
_global.interval = 100; // check at 1/10th sec intervals
_global.timeout = 2000; // timeout & restart after 5 sec
// this function will be run every _global.interval msec
// to increase and test _global.counter, when the counter
// reaches _global.timeout the movie will be restarted
_global.restart = function() {
_global.counter += _global.interval;
if (_global.counter > _global.timeout) {
_global.counter = 0;
_root.gotoAndPlay(1);
}
}
// start the restart "watcher" function
id = setInterval(restart, _global.interval);
}
-
Continuing Problem
Hey there, I'm also doing a project which requires a timeout,
This information is very helpful, however the same problem with the timeout time decreasing with more clicks remains.
I have multiple scenes which my buttons link to, would this be a factor why it's not working?
Feedback very much valued and appreciated.
-
Lifetime Friend of Site Staff
Put a trace statement inside the outer "if" statement and if you see your trace output appear more than once then you have a problem. If you've included the code above only once and you haven't changed it, then it should work.
-
Thanks for such a short time to reply.
I'm very new at actionscript.
I don't know what a trace statement is.
Cheers, Help still very much valued.
-
Lifetime Friend of Site Staff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|