Solved

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

Posted on 2010-11-17
8
624 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:dcolanduno
  • 5
  • 3
8 Comments
 
LVL 5

Expert Comment

by:GarrettChristopherson
Comment Utility
Is this script on a keyframe in the main timeline, in a document class, or in a movieClip?
0
 

Author Comment

by:dcolanduno
Comment Utility
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.
0
 
LVL 5

Expert Comment

by:GarrettChristopherson
Comment Utility
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.
0
 

Author Comment

by:dcolanduno
Comment Utility
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?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Accepted Solution

by:
GarrettChristopherson earned 125 total points
Comment Utility
I'm not sure that I fully understand with out seeing the timeline and full code for myself.
I recommend tracing out some values that relate to your timer, by placing the trace in the event handler

with the output from the following code sample, if you have a value of 0 for the counter appear more than once, then yes, my suggestion is still valid.
const secondstowait = 120;



var counter:uint = new uint(0);

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

    trace(counter + ' = counter');

    counter++;

	t.stop();

    t.reset();

    t.start();

	gotoAndStop("MainMenu");

}

Open in new window

0
 

Author Comment

by:dcolanduno
Comment Utility
Thanks, I'll give your idea a shot and see what happens.
0
 

Author Comment

by:dcolanduno
Comment Utility
Thank you so much! Once I saw the solution it made me go... "DUH!". Thanks for the help. :)
0
 

Author Closing Comment

by:dcolanduno
Comment Utility
Thanks a ton!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now