Link to home
Start Free TrialLog in
Avatar of dcolanduno
dcolandunoFlag for United States of America

asked on

How to effectively create screen saver Timer() in SWF using Actionscript 3.0

I have created a kiosk style application in Flash Professional CS5, but the last thing it needs its own, built-in, screen saver type routine.

I've been able to make it work ALMOST, but my big problem is that when it comes out of the blank screen it acts as if the timer doesn't reset and seems to be running, multiple, conflicting timers since the entire movie starts to act screwy and pops into screen saver mode on shorter and shorter cycles each time the screen goes blank and comes back out of the screen saving mode.

After a couple days of banging my head on my keyboard, I must be missing something. Maybe some kind person might spot the error using fresh eyes, or maybe I am just going about it the complete wrong way.

I'll try to post the code, maybe someone will see the snag for me?

 
const secondstowait = 120;

var bmd = new BitmapData(stage.stageWidth,stage.stageHeight,true,0x00000000);
var bmp = new Bitmap(bmd,'auto',true);

addChild(bmp);

var t = new Timer(secondstowait*1000);

t.addEventListener('timer',
function () {	
    t.reset();
    bmd.fillRect(new Rectangle(0,0,bmd.width,bmd.height),0xff000000);
    stage.addEventListener('mouseMove',
    function a () {
        bmd.fillRect(new Rectangle(0,0,bmd.width,bmd.height),0x00000000);
        t.start();
        stage.removeEventListener('mouseMove',a);
        stage.addEventListener('mouseMove',detector1);
    });
	t.stop();
	gotoAndStop("Saver");
});

t.start();

stage.addEventListener('mouseMove',detector1);

function detector1 (e:Event) {
	t.stop();
    t.reset();
    t.start();
	gotoAndStop("MainMenu");
}

Open in new window

Avatar of GarrettChristopherson
GarrettChristopherson

Is this script on a keyframe in the main timeline, in a document class, or in a movieClip?
Avatar of dcolanduno

ASKER

It is currently on the first keyframe on its own layer at the bottom of the stack. There is one other layer as well which has all the kiosk buttons and actions on it as well which is above it in the stack of layers.
does your movie run only on the first frame, or do you have more than one frame/keyframe on the main timeline.  If the latter is true, then you will continue to add new instances of your timer variable and event handlers, and that is most likely part of your issue.  When declaring variables on the timeline, I always have the playhead loopback to the second frame instead of the first, and declare the all other instances on the first frame, which "should" persist throughout your movie.  So when the playhead reaches the end of the movie, use gotoAndPlay(2), avoiding unwanted duplication of instances.
How it is constructed now is there is a layer which has all the buttons on it, which has all the Actionscript on the first frame as the 'Home' location, that is the kiosk 'homepage'. Then there is a layer at the bottom which has only the timer for the 'screensaver' which, when triggered, goes to the last frame in that layer which only has a blank screen.

Once that blank screen has any activity, it then pops back to the home screen.

I've tried doing reset on the timer, I've tried to remove the timer and replacing it. All efforts seem to just be piling up multiple timers on different clocks each time the screen saver triggers again.

Since there is never really a time when the actual timeline is 'running', would your suggestion still be valid?
ASKER CERTIFIED SOLUTION
Avatar of GarrettChristopherson
GarrettChristopherson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, I'll give your idea a shot and see what happens.
Thank you so much! Once I saw the solution it made me go... "DUH!". Thanks for the help. :)
Thanks a ton!