• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Detect User Idle Time or Inactivity (MouseEvent)

New Here ,
Aug 03, 2017 Aug 03, 2017

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.

Views

457

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 03, 2017 Aug 03, 2017

stage.addEventListener("stagemousemove",f.bind(this))

function ShowMsg() { 

alert("There is no activity"); 

function f() { 

clearInterval(this.to);

this.to = setTimeout(ShowMsg, 10000);

}

Votes

Translate

Translate
Community Expert ,
Aug 03, 2017 Aug 03, 2017

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 11, 2023 Apr 11, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2023 Apr 11, 2023

Copy link to clipboard

Copied

this.addEventListener(MouseEvent.MOUSE_MOVE,f)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 12, 2023 Apr 12, 2023

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2023 Apr 12, 2023

Copy link to clipboard

Copied

use

 

function f(e:MouseEvent):void{
// code

}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 12, 2023 Apr 12, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2023 Apr 12, 2023

Copy link to clipboard

Copied

LATEST

you're welcome 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines