PDA

View Full Version : combining Mouse.addListener and getTimer



gepo
August 4th, 2003, 01:42 AM
I need to get my movie to check if the user has click anywhere on the interface (doesn't matter were), if there's not click after 60second, I need to send the movie back to frame1.

I know is a combination of addListener(Mouse), onMouseMove
and getTimer. but I'm not very good at action script yet to combine the three. Any code sample and tutorials are more then appreciated.

THANKS
gepo

brainy
August 4th, 2003, 06:30 AM
what happens if he does click? this should basically work:


var timerID;
function stopTimer() {
clearInterval(timerID);
}
var mouseListener = { onMouseDown: stopTimer };
Mouse.addListener(mouseListener);
function gotoFrameOne() {
_root.gotoAndStop(1);
}
timerID = setInterval(gotoFrameOne,60000);

gepo
August 4th, 2003, 02:58 PM
yes it's working , Almost perfect
"what happens if he does click?..."
I need a way to tell timerID that if something is click to set itself back to 0 and start cheking the time again.

can you help me with that??
much thanks

gepo

brainy
August 4th, 2003, 03:19 PM
i assumed thats what you want... try this:


var timerID;
function startTimer() {
timerID = setInterval(gotoFrameOne,60000);
}
function resetTimer() {
clearInterval(timerID);
startTimer();
}
var mouseListener = { onMouseDown: resetTimer };
Mouse.addListener(mouseListener);
function gotoFrameOne() {
_root.gotoAndStop(1);
}
startTimer();

gepo
August 4th, 2003, 03:45 PM
thanks brainy, almost perfect again
there's alittle glich that I can seem to fiind. It looks like sometime var timerID; ;it reset istself and sometime it doesn't.
Could you take a look at my example??
much thanks

gepo

gepo
August 6th, 2003, 11:37 AM
Can't anybody help me clean this uP??????
thanks
gepo

claudio
August 6th, 2003, 12:30 PM
function startTimer() {
start = getTimer()/1000;
}
_root.onEnterFrame = function() {
elapsedTime = Math.floor(getTimer()/1000-start);
(elapsedTime == 60) ? _root.gotoAndStop(1) : trace(elapsedTime);
};
var mouseListener = new Object();
mouseListener.onMouseDown = startTimer;
Mouse.addListener(mouseListener);
startTimer();

gepo
August 6th, 2003, 01:32 PM
aaahhhhhaaaaaa perfect
obrigado Claudio,
it works perfectly
gepo

claudio
August 6th, 2003, 01:33 PM
De nada Gepo (welcome)
;)