Skip to main content
DeeViens
Participant
August 3, 2017
Answered

Detect User Idle Time or Inactivity (MouseEvent)

  • August 3, 2017
  • 1 reply
  • 704 views

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.

    This topic has been closed for replies.
    Correct answer kglad

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

    function ShowMsg() { 

    alert("There is no activity"); 

    function f() { 

    clearInterval(this.to);

    this.to = setTimeout(ShowMsg, 10000);

    }

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    August 3, 2017

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

    function ShowMsg() { 

    alert("There is no activity"); 

    function f() { 

    clearInterval(this.to);

    this.to = setTimeout(ShowMsg, 10000);

    }

    Inspiring
    April 11, 2023

    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

    kglad
    Community Expert
    Community Expert
    April 11, 2023

    this.addEventListener(MouseEvent.MOUSE_MOVE,f)