Solved

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

Posted on 2010-11-17
8
674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

717 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