Skip navigation
Paradigm
Currently Being Moderated

Using an inactivity timer

Apr 5, 2006 8:41 AM

I have searched the forums for timer hints and tips and although I've tried utilising some suggested code - I can't quite get this to work in my particular project.

I have a Flash presentation set up for our reception area. It consists of a looped movie clip which acts similar to a screen saver and doubles as a "WELCOME" sign (I have some text input script which places the day's visitors to the building within this "screensaver"). The presentation will also have various user-navigable sections explaining the company history, product ranges, personnel etc.

What I'd like is that when the user has finished exploring the corporate-based sections and there is no mouse activity for a set time (say 5 minutes) from anywhere in the whole presentation/time line, that Flash will jump back to the "screensaver" frame.

Can anyone recommend a simple way of achieving this, and does this involve including a "mouse-watch" script on every static frame? I'm from a design background, not a programming one, so if you can help, please explain the script in simple terms!
 
Replies
  • Currently Being Moderated
    Apr 5, 2006 9:43 AM   in reply to Paradigm
    Hi,

    this sure needs some kind of mouse watch script, but you can use onMouseMove and just place the code on the first frame of the main timeline, then it will affect the whole movie.
    Then you'll need an interval the length of the timeout, that calls the 'goto screensaver' action. On mouseMove, clear the existing interval and start a new one. You could use the (undocumented) setTimeout function for the interval (see the comments here).
    So altogether it might be something like this:
    --
    var timeoutID:Number;

    function timedOut () {
    gotoAndPlay("welcome");
    }

    onMouseMove = function(){
    clearTimeout(timeoutID);
    timeoutID = setTimeout(timedOut, 300000); // 300000 ms = 5 min
    }
    --
    That should be all. The code should be placed on the _root timeline's first frame.
    Maybe there's a better way to do this (the timeout is cleared and re-created on every mouse move), but as the mouse move is the event that shall stop the timeout, I don't see a better way here.

    hth,
    blemmo
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2006 9:52 AM   in reply to Paradigm
    To see if the timeOut function executes, add this in the function before the gotoAndPlay line:
    trace("timeout");
    This should echo "timeout" in the output window, when the function executes.

    Currently, you have to move the mouse to start the timeout, maybe you didn't do that? Should be better to start the timeout right after entering the frame. To do that, replace
    var timeoutID:Number;
    with this:
    var timeoutID = setTimeout(timedOut, 10000);

    If the message "timeout" appears, but the movie doesn't jump to the welcome scene, then there's something wrong with the gotoAndPlay function, so you should check if the name of the scene is right. It's case sensitive, so take care of that.

    greets,
    blemmo
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 21, 2006 2:28 AM   in reply to Paradigm
    Do you use Flash 8? I didn't mention that setTimeout is Flash 8 only, sorry. But it's almost the same as using setInterval, so it's quite easy to change it. Try if this works:
    --
    var timeoutID = setInterval(timedOut, 10000);

    function timedOut () {
    clearInterval(timeoutID);
    trace("timeout");
    gotoAndPlay("Welcome",1);
    }

    onMouseMove = function(){
    clearInterval(timeoutID);
    timeoutID = setInterval(timedOut, 10000);
    }
    --
    You forgot to start the interval/timeout again after it was stopped onMouseMove in the last code posted, but as said before, if you don't use Flash 8 it won't work at all. The difference to setInterval is only that setTimeout executes the function once, while setInterval executes it repeatedly, so we have to stop the interval after the first execution. And setInterval works since Flash 6.

    cheers,
    blemmo
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 21, 2006 2:45 AM   in reply to blemmo
    Hi Flasher!!!

    Try with this... It´s a freaky way ...

    Hope this help you.
     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2006 6:25 AM   in reply to Paradigm
    Hi,

    I'm not very familiar with scenes, probably there are issues with the timeoutID var between different scenes. You can try to trace a message in the mousemove event, to see if it executes. You could also trace the value of timeoutID there, to see if it's defined, and if it's the same timeoutID var created in the first frame.
    If you want the movie to play without interuption, disable the interval when a button was pressed. Then recreate the interval in the frame where the player stops. Otherwise the timeout will destroy the playback.

    hth,
    blemmo
     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    May 8, 2006 7:00 AM   in reply to Paradigm
    the frame that contains that code can only play once or you'll define intervals that never clear. to remedy you can use the code below. also, you should not use the goto function and you should not use scene info to navigate. use the goto method and frame labels as shown below:

    p.s. i never heard of setTimeout(). what makes you think that's a flash 8 function blemmo?

     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2006 7:40 AM   in reply to kglad
    hey kglad,

    according to the comments in the LiveDocs ( http://livedocs.macromedia.com/flash/8/main/00001717.html), setTimeout() was introduced in Flash 8, but accidentally not documented. I'm not sure if it's really necessary when there is setInterval(); it just makes clearInterval() in the called function redundant, as I see it, but it may avoid errors for lazy programmers .
    It's also featured in AS 3 ( http://livedocs.macromedia.com/labs/1/flex/langref/flash/util/package. html#setTimeout()), so I guess it was really just an accident that it is undocumented.

    greets,
    blemmo
     
    |
    Mark as:
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    May 8, 2006 9:04 PM   in reply to Paradigm
    hey thanks blemmo. and i thought you were crazy when i saw you using setTimeout().
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points