Skip to main content
March 31, 2010
Answered

Time out function when no mouse clicks or mouse holds detected

  • March 31, 2010
  • 1 reply
  • 336 views

Hi All,

Is there anything that i can add/remove to/from the following code to make  it not timeout while the mouse button is being held down too?

i have tried to modify Harry's code with the following:

import mx.utils.Delegate;

btn1.onPress = function(){
    clearTimeout();
    }

btn2.onPress = function(){
        clearTimeout();
        }

btn1.onMouseUp = function(){
    clearTimeout(nTimeoutId);
    setUserActivityTimeout()
    };
btn2.onMouseUp = function(){
    clearTimeout(nTimeoutId);
    setUserActivityTimeout()
    };
btn1.onMouseDown = function(){
    clearTimeout(nTimeoutId);
    setUserActivityTimeout()
    };
btn2.onMouseDown = function(){
    clearTimeout(nTimeoutId);
    setUserActivityTimeout()
    };
function setUserActivityTimeout():Void
{
    clearTimeout(nTimeoutId)
    nTimeoutId = setTimeout(Delegate.create(this, onUserInactivity), nTimeTolerance);
}

function stopTimer():Void
{
    clearTimeout(nTimeoutId)
}
function onUserInactivity():Void
{
    delete_root.onMouseUp;
gotoAndStop("exit_no");
}

Ned - im not skilled in programming enough to follow through with your advice:

"Look into disabling the timer until a mouse up event occurs."

something like:

if

MouseEvent.press == true

then

    clearTimeout(nTimeoutId)


????\

Pat

This topic has been closed for replies.
Correct answer Ned Murphy

If you don't want the setTimeout to be operating while the mouse is down, do not call the setUserActivityTimeout() function in your mouse down code.

Your mouse up code already has what I suggested.

To become skilled in programming you need to be able to realize what tools you have and how to use them.  That won't come from people handing you solutions unfortunately... you've gotta lose hair, sleep, and your marbles to earn that skill.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
March 31, 2010

If you don't want the setTimeout to be operating while the mouse is down, do not call the setUserActivityTimeout() function in your mouse down code.

Your mouse up code already has what I suggested.

To become skilled in programming you need to be able to realize what tools you have and how to use them.  That won't come from people handing you solutions unfortunately... you've gotta lose hair, sleep, and your marbles to earn that skill.