Solved

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

Posted on 2010-11-17
8
658 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
ID: 34158926
Is this script on a keyframe in the main timeline, in a document class, or in a movieClip?
0
 

Author Comment

by:dcolanduno
ID: 34159468
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
ID: 34159731
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dcolanduno
ID: 34164907
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
 
LVL 5

Accepted Solution

by:
GarrettChristopherson earned 125 total points
ID: 34165044
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
ID: 34172140
Thanks, I'll give your idea a shot and see what happens.
0
 

Author Comment

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

Author Closing Comment

by:dcolanduno
ID: 34172351
Thanks a ton!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

685 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