Copy link to clipboard
Copied
How to do this in html5 canvas ?
var _timer: Timer = new Timer(10000);
function Start(): void {
_timer.addEventListener(TimerEvent.TIMER, ShowMsg, false, 0, true);
_timer.start();
stage.addEventListener(MouseEvent.CLICK, StopTimer, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_MOVE, StopTimer, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_DOWN, StopTimer, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, StopTimer, false, 0, true);
}
function ShowMsg(e: TimerEvent): void {
trace("There is no activity");
}
function StopTimer(e: MouseEvent): void {
_timer.stop();
_timer.start();
}
Start();
Please help! Thanks.
stage.addEventListener("stagemousemove",f.bind(this))
function ShowMsg() {
alert("There is no activity");
}
function f() {
clearInterval(this.to);
this.to = setTimeout(ShowMsg, 10000);
}
Copy link to clipboard
Copied
stage.addEventListener("stagemousemove",f.bind(this))
function ShowMsg() {
alert("There is no activity");
}
function f() {
clearInterval(this.to);
this.to = setTimeout(ShowMsg, 10000);
}
Copy link to clipboard
Copied
Hello, I gather this works for HTML5, but in AS3 it throws an error at stage.addEventListener("stagemousemove",f.bind(this)):
"Scene 1, Layer 'Actions', Frame 1, Line 2, Column 43 1061: Call to a possibly undefined method bind through a reference with static type Function."
is there a version compatible with AS3
Copy link to clipboard
Copied
this.addEventListener(MouseEvent.MOUSE_MOVE,f)
Copy link to clipboard
Copied
Thanks for this reply, (and your many others). This resolved the compile error, but produces the runtime error:
"ArgumentError: Error #1063: Argument count mismatch on TestApp_fla::MainTimeline/f(). Expected 0, got 1.". Not sure why it thinks it's getting an argument for f().
From the following code:
this.addEventListener(MouseEvent.MOUSE_MOVE,f)
function GoHome() {
gotoAndStop(1);
}
function f() {
clearInterval(this.to);
this.to = setTimeout(GoHome, 10000);
}
Copy link to clipboard
Copied
use
function f(e:MouseEvent):void{
// code
}
Copy link to clipboard
Copied
Perfect. This is such an elegant solution for the common need for an idle timeout. I hope all the other threads asking about this can find your post. Thank you.
Copy link to clipboard
Copied
you're welcome