Solved

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

Posted on 2010-11-17
8
651 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 …
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

792 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