Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Timers/Clock



Look...Im trying to make a timer or counter if you will. Basicallly a clock that counts down from whatever time I give it. I have a feeling this will be an arduous process. Most of it will AS except for the graphic part. Can anyone give me some ideas on how I would do the AS for this.

[Im thinking (out loud of course) that I will basically need to do some graphic representation of the numbers 0-9 and then create some kind of MC that when ever the script tells it it will display the next number. the problem im thinking of is that I would need to create or use some kind of component. Which im absolutely wretched at.}]

Any ideas or comments.
Thanks



Ultrashock Forums > Flash > Flash Newbie
Posted on: 2005-06-27


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Mobile Phone Clock - Simple Digital 24 Hour Clock
Hi

I need to make a digital clock/watch for a mobile phone flash demo. I know there are lots of clock on flash kit but they all have seconds and minutes - I need just hours and minutes! - The clock also has to be 24 hour.

I've tried taking the code from a flash kit clock and tweaking it but it seems to screw up - for example 07.03 comes out as 7.3 - looks really naf like that!

If anyone can help me out with a source file or some code I would be most greatful!

<b>I Need A Clock, Please Help Me, Need Full Information To Make A Flash Clock</b>
need some info please help. heed some help


i am swedish and 13 winters old nEEd english email-friend please nobody in sweden doesent understand flash , so badly....

........
.... ::: CHASER ::: ....

Countdown Clock (sync With Server Clock In .asp) PLEASE HELP
I used Senocular's awesome countdown clock tutorial found here:

http://www.kirupa.com/developer/mx/countdown2.htm

but I need to figure out how to sync it to my server's clock (I understand I must do this in a .asp file and then load that into flash).

Using vbscript this is what I tried, but obviously it doesn't work I think I may need to convert it completely to seconds first before bringing it into flash:

<%
Dim MyTime
MyTime=now()
response.Write("time="&MyTime)
%>

Does anyone have any ideas?

Thanks so much!

Regarding Timers
Simply put, I need to execute the timer on frame 1, then over a certain time (10secs), gotoAndPlay(2).... then, there's a button at frame 2, which will go to frame 1 on release. But.. I discover that the timer is still going on at frame 1.... which means the timer is always over 10secs, which causes it to return to frame 2 immediately after clicking the button.

Any solutions to that? Please help

Using Timers
I would like to know how to use a timer so that when a button is clicked on the main timeline, after 2 seconds something happens.

Is this how to do it?
declare a variable that equals the current time (if so how/where do I declare it?) eg

currenTtime = getTimer()

The attach a script to the button, which on a mouse event waits for 2 secconds before carrying out the action
(I dont know how to code this, must the currentTime variable be recalled, ifso how?)

on (release){
If (getTimer() > currentTime + 2000 ) {
gotoAndPlay (35) ;
}
}

Hopefully you can help, it would mean a great deal to me, thanks.

Timers Are Mean
whatwrong with my code here

-------------------code---------------------
if ((getTimer() - watch) < 1000) {
gotoAndPlay (9);
}
else{
gotoAndPlay (11);
}
-------------------code----------------------

Using Timers?
Hi everyone,


I’m wanting to make a timer using minutes and seconds to count down to "0", then I’m wanting it to go to a specific frame and play.

I think I saw it a while back but cant remember where exactly, I’m sure I have to use getTimer, but I have never used it before.

Can someone help me out?

aiden,
sagnokak@aol.com

Timers
Before I start - just to let you know that I don't know Flash MX at all - I am asking on behalf of someone else (who's still novice just not as novice as myself!)

We are making a sort of quiz type thing, and was wondering how to give an amount of time that they have to answer the question in.

Simple I know, but seing as I don't know flash and my mate doesn't have the Internet himself, it's harder to work it out... ;-)

TIA

Richie

Best Way For Timers?
What's the best way for timers? I'm thinking a basic do while loop using a variable for a counter...

what else can be done?

Timers
Right, I have a dynamic text that can only hold numbers, with the variable time. This is part of an mc called Timer which has the following actionscript:

onClipEvent (load) {
seconds = 90;
time = seconds;
running = false;
restart = function () { countdown = getTimer()+1000*seconds;running = true;time = seconds;};
}
onClipEvent (enterFrame) {
if (running) {
if (time == 0) {
running = false;
_root.play();
} else {
time = Math.round((countdown-getTimer())/1000);
}
}
}
Then in the script for the frame, I have Timer.restart();
The timer is meant to count down from 90, then go to the next frame once it reaches 0.

But the only problem is, the timer won't work! Can anyone give me some advice on where I am going wrong?

Timers - Help
Hi all,

I've created a timer in an mc == timer with the variable called time. It works. Code ==
onClipEvent (enterFrame) {
time = MaxTime
MaxTime = 20;
StartTime = getTimer()+1000;
countDown = Math.round(MaxTime-StartTime/1000);
}
onClipEvent (enterFrame) {
if (countDown == 0) {
_root.gotoAndStop("question");
}
}

I need the timer to start counting down in Frame 2, not from onload in Frame 1. I have tried - unsuccessfully and over XXX hours to define a function for it, but can't crack it. Can anyone stop my forthcoming nervous breakdown please me???

Ta muchly,

Megs

Timers?
Is there any way that I can set up a timer in flash? I'm trying to create a realistic conversation between two people in a dynamic textbox, but I am not sure how to set a timer between their conversation pieces.

Timers
Hi, atm, I'm using a system which detects how many frames have elapsed, and every x frames, reduces the timer by 1. However, on computers with slow FPS, you get ages on the game, instead of 60 seconds!

Anyone help?

Timers
I have constructed a game and I am setting a timelimit on it via a countdown timer.

I firstly created the countdown timer in a small application on its own and it worked fine. When I brought it into the game it ceased to work, am I missing something. Here is my code, on the main app there is a Dynamic Text box called timer_txt.


Code:
//Record the starting time.
var startingTime = new Date();
//Count down from 60 seconds
var maxTime = 60

//Check the elapsed time during each tick of the frame rate.
this.onEnterFrame = function(){
//Determine the elapsed time.
var elapsedTime = new Date().getTime() - startingTime.getTime();
//Convert from milliseconds to seconds and round to the nearest second.
elapsedTime = Math.round(elapsedTime / 1000);
if (elapsedTime >= maxTime){
this.timer_txt.text = "0";
gotoAndPlay("OutOfTime");
}else{
this.timer_txt.text = maxTime - elapsedTime;
}
};
Any help greatly recieved.

Timers
I am trying to make a game at the moment. I have found a code to make a timer count down to 0, however I cant make it take the user to a slide when the timer gets to 0. All my attepts at creating a code have failed miserably =(. Any ideas?

URGENT Regarding Timers
I created a timer, then I create a dynamic text box to display the time in the text box. The problem is I only know how to show the time to go from 0 - 90 secs. What I need is the time to countdown from 90 - 0 sec. There is also a problem where three decimal places are shown, how do I cancel all the decimal places out? Anybody have any ideas? This is my code...

x = getTimer();

if ((x+90000)<getTimer()) {
gotoAndPlay ("TimeUp");

}else{

time=getTimer()/1000; //time is the dynamic text box name
//This is also the code to make
//the time count from 0 - 90 secs

}

Urgent Timers
I've got a problem with my timer. I need to only start the timer after I have clicked a button on the first frame (which goes to the second frame after clicking), and on the second frame, the timer then will start. But the problem is the timer already started once I execute the file, and the time that I take to click on the button is included. How do I start the timer ONLY after the button is clicked on? Help anybody?
Thanks

Timers Within Flash?
...is there anyway in action scripting that i could set a timer? for instance i could go to a frame and stop on it for 5 seconds, and then go to the next on and pause for 5 seconds...i know this technique would be easy, but on each frame there is some heavy scipting that goes on in each frame, so it complicates everything...any ideas?

Question About Timers
how do u set a timer and then access the current time?

for example, i want a timer to be set to zero on a certain mouseover, and then a telltarget to occur when it reaches say....1.5 min

what is the as for this?

Using Timers In Flash 6?
Does anyone know how I can make a timer with action script? Is what I need to do exactly is....

The only thing in the scene is 1 layer with 3 frames. I'd like to know if there is action script I could put on the first frame that made it stay on frame 1 or 2 for say 10 seconds, then it would go to frame 3 where it would be told to jump to another scene!?!? Thanks in advance all

A Little Help W/ Timers And Masks?
i would like to do a grid of 25x25 px cells that reveal an image below them

see example:

http://www.capacitornetwork.com/CDN2002_c.html

i have tried and failed...

any help in pointing me to some script or tutorial?

i took the route of trying to create a button that has a timer on a mask. then duplicating it over an image.

right direction?



thanks in advance!

Timers And The Sort
uh hey guys,

just wanted to know
how to add a timer-based actions,

like say, if it is already 5 seconds on a current frame,
then go and play on the next

can any1 help?

thnx a bunches!!!

[F8] Lives With Timers. Help
Hello.

I have a game. Inside the game on a scene, there is a timer showing 5 seconds getting counted down.

This is the script on the first frame of the scene for the timer:

Code:
tenSecondTimer = setInterval(countDown,1000);
timeLeft = 5;
function countDown(){
timeLeft--;
_root.displayTime.text = timeLeft;
if (timeLeft == 1) {
displayTime.textColor = 0xFF0000;
}
if (timeLeft == 0){
buzz = new Sound(this);
buzz.attachSound("buzz");
buzz.start(0, 1);
gotoAndPlay("restart",1);
clearInterval(tenSecondTimer);
}
}


This script works well and does everything properly. When the time runs out from 5 seconds, a buzzer sound is sounded to inform the player she got it wrong. It then directs them to the "restart" scene. However, I want to include lives in the scene.

On the stage, I also have lives. When the person playing the game, and lets say, presses the wrong answer from a multiple choice question it subtracts a life from the currentLives variable. This is the script that is attached to the wrong answer button:

Code:
on (release) {
clicker = new Sound(this);
clicker.attachSound("clicker");
clicker.start(0, 1);
buzz = new Sound(this);
buzz.attachSound("buzz");
buzz.start(0, 1);
if (currentLives == "3") {
lives.textColor = 0xEAEA00;
livesText.textColor = 0x959500;
lives.text = currentLives -= 1;
}
else if (currentLives == "2") {
lives.textColor = 0xFF0000;
livesText.textColor = 0x990000;
lives.text = currentLives -= 1;
}
else if (currentLives == "1") {
gotoAndPlay("restart", 1);
}
}


Now this script works great on wrong answer buttons. It makes a buzzer sound to inform the player that he/she got the answer wrong. It then changes the color of the lives text. If the player has 3 lives left, the color of the lives is green. If he/she has 2 lives left, the text turns yellow and if the player has only one life left, it turns red. It works good on multiple choice questions.

However, I want to put it on the scene where the timer is on. I need to combine the two scripts so that when the time runs out, it subtracts a life and restarts the scene to give the player another try. After the player has 1 life left and the time runs out, I need it to go to the scene called "restart".

Thanks in advance to whoever replies.

Buttons & Timers
I'm a Flash designer so I do my best at code...and this one has me fickled.

I have a series of timers inserted in my timeline to pause at selected points for a few seconds, then move to the next point (the last sends them back to a menu page). They work great...

But I want to include a button on the page that will allow the viewer to bailout and go back to the menu (rather than viewing the entire sequence)

I do a standard "goto on release" to the desired framelabel in the button script, yet when I click the button, it advances to each timer point, then sends me to the menu page.

Seems like I have a conflict between timer and button script...any help??

thanks,

john

2 Timers Not Working
Hi. I am new to actionscript but am wading my way through slowly with examples and books.

What i have/want:
I basically have a race through a maze on the left, and another race on the right side of the window. Below each is a timer. When one completes, the timer should stop for that one. When they are both done, you should be able to compare the times.

My problem:
I found code for a timer off the movies section. I can get one timer to work fine, but with 2 I have problems. I put code for each timer on its own layer. Each timer can work if I comment out the other, but not together. If I try to use both layers(timers), then only one timer will count, the other stays at zero.

My timer code: (stole from the movie section)

PHP Code:



function startTimer() {     
    this.onEnterFrame = Rtimer;
    } 

function stopTimer() {     
    delete this.onEnterFrame; 
    } 

    
function timer() {     
    elapsedTime = getTimer()-startTime;
    elapsedHours = Math.floor(elapsedTime/3600000);
    remaining = elapsedTime-(elapsedHours*3600000);
    elapsedM = Math.floor(remaining/60000);
    remaining = remaining-(elapsedM*60000);
    elapsedS = Math.floor(remaining/1000);
    remaining = remaining-(elapsedS*1000);
    elapsedH = Math.floor(remaining/10);
    if (elapsedHours<10) {
        hours = "0"+elapsedHours.toString();
    } else {
        hours = elapsedHours.toString();
    }
    if (elapsedM<10) {
        minutes = "0"+elapsedM.toString();
    } else {
        minutes = elapsedM.toString();
    }
    if (elapsedS<10) {
        seconds = "0"+elapsedS.toString();
    } else {
        seconds = elapsedS.toString();
    }
    if (elapsedH<10) {
        hundredths = "0"+elapsedH.toString();
    } else {
        hundredths = elapsedH.toString();
    }
    _root.timer_txt = hours+":"+minutes+":"+seconds+":"+hundredths;
    //_root.Rtimer_txt = hours+":"+minutes+":"+seconds+":"+hundredths;
};



startTime = getTimer();
onEnterFrame = function () {
    elapsedTime = getTimer()-startTime;
    elapsedHours = Math.floor(elapsedTime/3600000);
    remaining = elapsedTime-(elapsedHours*3600000);
    elapsedM = Math.floor(remaining/60000);
    remaining = remaining-(elapsedM*60000);
    elapsedS = Math.floor(remaining/1000);
    remaining = remaining-(elapsedS*1000);
    elapsedH = Math.floor(remaining/10);
    if (elapsedHours<10) {
        hours = "0"+elapsedHours.toString();
    } else {
        hours = elapsedHours.toString();
    }
    if (elapsedM<10) {
        minutes = "0"+elapsedM.toString();
    } else {
        minutes = elapsedM.toString();
    }
    if (elapsedS<10) {
        seconds = "0"+elapsedS.toString();
    } else {
        seconds = elapsedS.toString();
    }
    if (elapsedH<10) {
        hundredths = "0"+elapsedH.toString();
    } else {
        hundredths = elapsedH.toString();
    }
    _root.timer_txt = hours+":"+minutes+":"+seconds+":"+hundredths;
    //_root.Rtimer_txt = hours+":"+minutes+":"+seconds+":"+hundredths;
}; 




The other set of code in the other layer is identical, but with an R added to the function names.


Any help would be greatly appreciated.

Variable Timers
Hi there,

I'm trying to create an application that uses the Timer class, but I want the time interval (delay) to change between each TimerEvent.TIMER event. For example:

- "1" is displayed after 2 seconds.
- "2" is displayed after 5 seconds.
- "3" is displayed after 15 seconds.
- .. and so on.

I have tried something like this, but didn't seem to work:


Code:
public function initApp():void
{
var timer:Timer = new Timer(timerArray[counter], 0);
timer.addEventListener(TimerEvent.TIMER, onTimer);
//timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer.start();


}

public function onTimer(event:TimerEvent):void{
number = number + 1;
time = time + 1000;
counter = counter + 1;
}
***timerArray is a simple array that stores different delay timings.

Is there any easy way to do this?

Thank you in advance!

Tbeanz

Problems With Timers
Hi All,

Im having a bit of a problem with a timer based animation in IE7.

heres the code:


ActionScript Code:
sequenceTimer = new Timer(12,400)
sequenceTimer.addEventListener(TimerEvent.TIMER_COMPLETE, changePicture);
sequenceTimer.start();

As you can see, a timer is created then after a few seconds an event is triggered.
This works fine in Flash, and when i upload it to my site it works fine in FireFox, Safari and Opera... but in IE7 it takes 4 times as long for the event to trigger and it almost looks like the flash isnt working at all unless you patient!

Has any one else had this problem? is it an IE7 bug or a problem with my code?

Cheers

Timers Vs EventListeners
Hello all -- I am fairly new to Flash full stop but I learned AS2 basics and then moved onto AS3. I was following a tutorial on AS3 but when I revised the ActionScript, I questioned why the "tutor" had used the actionscript he had used. At the beginning, he used a timer attached to an eventlistener attached to a function! I didn't see the point of this so changed it into the one eventlistener. Anyway... below is the original actionscript followed by my revised version. This is for a simple navigation bar where a "glowing bar" follows the mouse movement.

All I'd like to know is if there are any advantages to the "tutor"'s version with the timer than to my simpler eventlistener version.

Many thanks,
max.

---------------------------------------
Tutor's version
---------------------------------------

var timer:Timer = new Timer(25);
timer.addEventListener(TimerEvent.TIMER, followF);
timer.start();

function followF(event:Event):void{
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseF);
}

function mouseF(event:MouseEvent):void{
master_mc.glow_mc.x = stage.mouseX-63;
addEventListener(MouseEvent.MOUSE_MOVE, updateF);
if(mouseX<=63){
master_mc.glow_mc.x = 0;
}
if(mouseX>=340){
master_mc.glow_mc.x = 300;
}
}
function updateF(event:MouseEvent):void{
event.updateAfterEvent();
}

---------------------------------------
My version
---------------------------------------

addEventListener(MouseEvent.MOUSE_MOVE, mouseF);

function mouseF(event:MouseEvent):void{
master_mc.glow_mc.x = stage.mouseX-63;
if(mouseX<=63){
master_mc.glow_mc.x = 0;
}
if(mouseX>=340){
master_mc.glow_mc.x = 300;
}
addEventListener(MouseEvent.MOUSE_MOVE, updateF);
}
function updateF(event:MouseEvent):void{
event.updateAfterEvent();
}

How Do You Manage Timers?
What are your guys' methods of using timers? Currently I'm going through the whole process of constructing new timers and eventlistener functions every time I need to animate or delay something, which means a lot of unique and creatively named variables, but is there a better way like being able to use one running timer for my whole project (I wouldn't mind working with one time interval) that functions can jump in and out of at will?

Thanks

Loader Timers
i have to load a sequence of external swf files inside a MC

I have no problems with that, but i want to, load the first, and after is fully loaded, make a timer that waits 30 seconds, and then loads the second external swf file.

i dont have the original fla files of the external swf files

what can i do?

Help With Timers In Game
in my game i would like a timer counting up telling how long youve played, i would like the code to be in the time line and a dynamic text box holding the timer variable, how do i do this?

also, i would like a timer counting down, and when it reaches 0 to send you to a lose frame, how would i do this?

thank you,
thejoeknows

Multiple Timers?
Hi.

As I´m a decent flash-programmer g r a p h i c a l, i´m having problems with the coding-part.

I´m using this peace of code to start at timer.


_root.pausebutton._visible = 0;
//
function restartTimer() {
    hours = "00";
    minutes = "00";
    seconds = "00";
    milli = "00";
    buttonPressTime = getTimer()/1000-pauseLength;
    pause();
}
//
function pause() {
    pauseTime = getTimer()/1000;
    timing = false;
}
//
function unpause() {
    unpauseTime = getTimer()/1000;
    pauseLength = (unpauseTime-pauseTime)+pauseLength;
    timing = true;
}
//
_root.onEnterFrame = function() {
    totalTime = getTimer()/1000-pauseLength;
    goTime = totalTime-buttonPressTime;
    //
    if (timing) {
        hours = Math.floor(goTime/3600);
        minutes = Math.floor((goTime/3600-hours)*60);
        seconds = Math.floor(((goTime/3600-hours)*60-minutes)*60);
        milli = Math.floor((gotime-(seconds+(minutes*60)+(hours*3600)))*100);
        if (seconds<10) {
            seconds = "0"+seconds;
        }
        if (minutes<10) {
            minutes = "0"+minutes;
        }
        if (hours<10) {
            hours = "0"+hours;
        }
        if (milli<10) {
            milli = "0"+milli;
        }
    }
};
unpausebutton.onRelease=function() {
    unpause();
    pausebutton._visible = 1;
    unpausebutton._visible = 0;
}
pausebutton.onRelease=function() {
    pause();
    unpausebutton._visible = 1;
    pausebutton._visible = 0;
}
reset.onRelease= function() {
    restartTimer();
    pausebutton._visible = 0;
    unpausebutton._visible = 1;
}


Now I´m having 2 problems since I want the timer to work on a multiple sets of frames. If i have the above piece of code on 2 frames, the 2 timers will follow eachothers. So the first question is:
How do I seperate the 2 timers from eachother?

The second problem is that when I move from frame 1 to frame 2, and then back to frame 1 (with a timer), I want the STOP button to show if the timer is ticking, but now the START button shows evert time I enter the frame.


Thnxs.

/Petter

As Timers To Implement Delays
I am wanting to delay a frame by two seconds using as, with the onClipEvent(enterFrame) but how do i go about doing this without using the getTimer syntax that reads the time from the start of the movie. Is there any way to reset the timer value so it starts from a specified frame?

See Barely Legal First Timers...
...to actionscripting in Flash MX:

My main.swf file contains a BG music track, and I'm loading popups containing audio material into level 1. I want the BG ambience to fade down whenever a movie is loaded into level 1, and fade back up whenever level 1 is empty.

Ideally I want to control this from my main.swf (because I don't want to have to go back and edit the 50+ swfs that load into level 1)

Any ideas?

Listeners Keypresses And Timers
Hello, Im currently attempting to recreate R-Type in Flash MX. Ive made alot of programs in Flash, so i am familiar with it, and basic AS, but im kinda lost when it comes to games.

Anyway, im sure im gonna have quite a few questions im sure you guys could help me with in 2 seconds flat, so i'll keep them all in this thread.

My first problem:

Im trying to create the "big beam" The powerful fire that used to be shot by holding fire (to build up) then letting go to release, in the origional R-Type.

Ive decided to just use a seperate key for this rather than the same button ive used for all the normal firing. please try and bear with me, ive never used listeners before, and neither have i used getTimer in a situation anything like this.

This is what i came up with to get the "big beam"(fire6) shooting on the release of control.

code: myListener = new Object();
myListener.onKeyUp = function() {
if (Key.isDown(Key.CONTROL)) {
setProperty (_root.fire6, _x, getProperty(_root.Spaceship, _x)+90);
setProperty (_root.fire6, _y, getProperty(_root.Spaceship, _y));
with ( _root.fire6 ) {gotoAndPlay (2); //plays sound
}
}
};
Key.addListener(myListener);

This has been put in a frame in the main timeline, it kinda works, but not how i want it to. When you press control it does nothing, howeva if you hold control and then press another key(eg M) on the release of M the beam will fire.
What do i need to do to this to get it firing on the release of control? and how would i go about including a timer that starts when control is pressed, then when released the value of the timer is passed to the x and y values of the "big beam" mc (fire6)?

I'll include the fla incase it makes it easier for you guys.The code duscussed is in frame 1 of the actions label, other revelent code is on the ship itself and the instances of the weapons (left of stage)

Thanks
Scott

Video Playback Timers
Hey people,

For a video on a website I've decided to make use of timers to set an interval in order to rewind and fast forward at an ever-increasing speed (ie the longer the buttons are held down, the faster the video moves).

For example, on a rewind button function I set the videoDirection to -1 to make it go backwards, then below this I create a setInterval called "timer_vid1" and set properties to "setDirection" and "60".

I also have another timer "timer_vid2" which is also set up for "setDirection" but "500" for the interval as I want to wait half a second each time.

Was wondering..where abouts should I put it in the script? I tried it a few days ago outside the button function - inside an "on enterFrame" script
but then this means that it applies itself to every function - even playing and stopping because it occurs on the one and only frame that is in the
movie.

code:
btn_rewind.onPress = function() {
videoDirection = -1;
clearInterval(videoTimer);
videoTimer = setInterval(setDirection, 60);
}

function setDirection() {

if(videoDirection == 1) {
video.nextFrame(); }
else {
video.prevFrame();
}


Am I supposed to declare the timer at the start of the script and then recall it next to the "timer_vid1" timer?

Thanks,
Ste

2 Timers Displaying Different Times
I have a Flash training app in which students can choose a particular module from a list. In the training app, I have 2 units which have timers on them. These timers are supposed to count the time that its unit has been turned on. The problem I'm having is that if I start one of the units, when I visit the other unit, it is displaying the first one's time instead of its own.

I also want to be able to stop either of the timers when the user toggles one of the switches while the other unit is still running, thus having 2 separate timers that run on their own.

Finally, I want to be able to reset the timers when the user selects a new module. Right now, because getTimer starts when you begin the Flash piece, it is showing the time since the Flash file started instead of starting back at 0:00.

What is the best way to accomplish what I'm trying to do?

Chris

Slow/Lagging Timers
Hello,

I am coding in AS3 and am experiencing a very laggy Timer that I use to run some simple scaleX/Y animations. When i have a MOUSE_MOVE event listener in the flash, for example, the timer completely pauses while I am moving the mouse, and resumes when I stop moving mouse. Why could this be happening?

How To Stop All Running Timers At Once?
I'm working on a game that has lots of timers in different classes/objects.
Once a player has finished a level i'd like to stop all those timers. There are quite a lot of them, so i was wondering if AS3 has something that can stop and reset them all, instead of stopping/resetting them all 1 by one very specifically on the event of a finished level. (Which could be very complicated to do)
Does anyone know if something like that exists or how that is generally done or if there are any solutions/workarounds to this?

I Hate Timers Down Anybody Know The Process?
Hi,

I am having much trouble with the Timer. I add one to the object list and make it where the functions can all access it (I think!). Problem is, I can never seem to remove the listener, and all of my scene transitions get screwed.

In those mouse-down functions up top, when you press the button to call one of those, it keeps throwing an error "parameter child must be non-null"... and I seem to be having all kinds of trouble with removing the content function there as well...

Am I doing this right? Could you check out my code and see if I have all of the relationships in order and what-not. All I'm trying to do is transition from one function to the next and be able to use a back, forward and pause button. This is so confusing to me and my head is spinning!


PHP Code:



package  
{
    import fl.motion.easing.Back;
    import flash.display.*;
    import flash.display.MovieClip;
    import caurina.transitions.*;
    import flash.events.*;
    import flash.utils.Timer;
    
    public class Main extends MovieClip
    {
        public var trinidad        :Trinidad;
        private var hattera         :Hattera;
        private var botanique       :Botanique;
        private var backButton      :SimpleButton;
        private var pauseButton     :SimpleButton;
        private var forwardButton   :SimpleButton;
        private var movieNumber     :uint;
        public var timer:Timer = new Timer(5000);
        
        public function Main():void
        {
            init();
        }
        
        private function init():void
        {
            controlBar.back.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownBack);
            controlBar.forward.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownForward);
            controlBar.pause.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownPause);
            
            startTrinidad();
        }
        
        private function onMouseDownBack(e:MouseEvent):void
        {
            if (movieNumber == 1)
            {
                timer.removeEventListener(MouseEvent.MOUSE_DOWN, timerHandler1);
                removeChild(trinidad);
                //startBotanique();
            }
            else if (movieNumber == 2)
            {
                timer.removeEventListener(MouseEvent.MOUSE_DOWN, timerHandler2);
                removeChild(hattera);
                //startTrinidad();
            }
            else(movieNumber == 3)
            {
                timer.removeEventListener(MouseEvent.MOUSE_DOWN, timerHandler3);
                removeChild(botanique);
                //startHattera();
            }
        }
        
        private function onMouseDownForward(e:MouseEvent):void
        {
            
        }
        
        private function onMouseDownPause(e:MouseEvent):void
        {
            
        }
        
        private function startTrinidad():void
        {
            movieNumber = 1;
            trinidad = new Trinidad();
            addChild(trinidad);
            setChildIndex(trinidad, 0);
            trace(movieNumber);
            
            timer.addEventListener(TimerEvent.TIMER, timerHandler1);
            timer.start();
        }
        function timerHandler1(e:TimerEvent):void
            {
                removeChild(trinidad);
                startHattera();
                timer.removeEventListener(TimerEvent.TIMER, timerHandler1);
            }
        
        private function startHattera():void
        {
            movieNumber = 2;
            hattera = new Hattera();
            addChild(hattera);
            setChildIndex(hattera, 0);
            trace(movieNumber);
            
            timer.addEventListener(TimerEvent.TIMER, timerHandler2);
            timer.start();
        }
        function timerHandler2(e:TimerEvent):void
            {
                removeChild(hattera);
                startBotanique();
                timer.removeEventListener(TimerEvent.TIMER, timerHandler2);
            }
        
        private function startBotanique():void
        {
            movieNumber = 3;
            botanique = new Botanique();
            addChild(botanique);
            setChildIndex(botanique, 0);
            trace(movieNumber);
            
            timer.addEventListener(TimerEvent.TIMER, timerHandler3);
            timer.start();
        }
        function timerHandler3(e:TimerEvent):void
            {
                removeChild(botanique);
                startTrinidad();
                timer.removeEventListener(TimerEvent.TIMER, timerHandler3);
            }
    }
    


Clarification On Using Timers For Animation
Hello,

I am using timers to animate my sprites. Each sprite has has a different timer. Every time a timer fires for a sprite, I update sprite with a new bitmap image. Considering all of this, how does Flash take care of buffer updates? That is, will the update to the screen buffer be done all at one time even though the timers are firing independently? Or would the screen buffer be updated at different times, for example when Flash is drawing to the screen? I've read different accounts on this.

Thanks.

Video Playback Timers
Hey people,

For a video on a website I've decided to make use of timers to set an interval in order to rewind and fast forward
at an ever-increasing speed (ie the longer the buttons are held down, the faster the video moves).

For example, on a rewind button function I set the videoDirection to -1 to make it backwards,
then below this I create a setInterval called "timer_vid1" and set properties to "setDirection" and "60".

I also have another timer "timer_vid2" which is also set up for "setDirection" but "500" for the interval as I want to wait half a second each time.

Was wondering..where abouts should I put it in the script? I tried it a few days ago outside the button function - inside an "on enterFrame" script
but then this means that it applies itself to every function - even playing and stopping because it occurs on the one and only frame that is in the
movie.

btn_rewind.onPress = function() {
videoDirection = -1;
clearInterval(videoTimer);
videoTimer = setInterval(setDirection, 60);
}

function setDirection() {

if(videoDirection == 1) {
video.nextFrame(); }
else {
video.prevFrame();
}

Am I supposed to declare the timer at the start of the script and then recall it next to the "timer_vid1" timer?

Thanks,
Ste

Movie Clip Timers
Okay, I have a movie with a lot of movie clips that I want to play in a certain order -- more specifically when the previous movie clip is finished playing. Is there a practical way to use actionscript to achieve this instead of me adding hundreds of frames to all my movie clips so they they'll play successively. Is there a whenDone (just made that up haha) function or something? I could try writing my own function, but I'm not that experienced with AS yet. Thanks for the help

How Do I Use Timers To Repeat A Function, And What Else R They For?
How can I use a timer to repeat a function, and what else do timers "do"

Timers, Events, And MainLoops
Hey all again,

Sorry for all the posts recently but i really appreciate the help you've all been giving.

This time I was wondering about the pro's/cons of using Timers, Events, and MainLoops.

In older Actionscript 2 games that I've built, I had a main loop than ran onEnterFrame to update certain things (movement, etc).

Since I don't want to be a slave to the end user's framerate, I was thinking of using a Timer, where lets say 10 times a second, it will update all the things that need updating.

But in OO AS3.0 World, this still seems like a wrong approach.

A couple of ideas were to use Events and Timers. So every NPC in the gameworld has their own personal Timer or a ProcessTimer, and at each interval, the NPC takes action on whatever needs to have action taken.

For example, a BadGuy is standing all alone in a field. His individual timer is running and every interval we make a random choice to change direction, if we change direction, we animate that and then check his field of view to see if he sees anything. If not, we just keep the timer running and let him continue his sentry duty.

If the player runs into the field of view, we should broadcast an event that the BadGuy is listening for and will then take action at his next Timer interval.

It seems to me that this way, every object in the gameworld is responsible for itself and it's own processes and does them when necessary. My worry is that when i have 20 NPCs all running their own Timer's and listening to events etc that I'm going to get a huge performance hit.

I also want to be able to quickly pause the game, so with this approach I would have to loop through all my actors and turn off their individual timers too.. or does a simple Stop(); actually stop everything thats going on?

Any ideas, thoughts, comments?
Thanks!

Tween Class Timers
http://www.zedia.net/timing-an-anima...ctionscript-3/

I was reading that post, but my question is, what if you want to have various timers that start a tween rather than just the one timer? Is there a way to specify a timer to specific tween?

I am new to AS so sorry if there is a simple answer to this, I am trying to experiment with AS tweens rather than timeline so I am doing as much research as I can.

Thanks!

Is There A Downside To Using The SetInterval Function To Set Timers, Etc?
What I mean is if it puts to much pressure on the processor. Can I for example, set 30 setintervals, without the processor losing performance power or the application producing errors, etc.?

thanks

Migration Issues With _root And Timers
I am working on migrating an AS2 project to AS3 and have hit a wall. I think that the problem lies in a mouse_over event that is not firing.

I was using _root in my old script. Does this migrate to AS3?

My next problem is a little more complicated. I am using Timers and I think that is messing me up pretty good. My mouse_over event calls a times, which calls a function that changes a variable to the name of the movieclip that triggered the mouse_over event. If that makes any sense.

Here is a bit of code to clarify further:

code:

function bgover(event:TimerEvent):void {
trace("bgover fired");
accordionTrigger = true;
over = this.parent.name;
trace("over: " + over);
}

function setTimer(event:MouseEvent):void {
trace("setTimer fired");
tTimer.addEventListener(TimerEvent.TIMER, bgover);
trace("this.parent.name: "+ this.parent.name);
tTimer.start();
}

function stopTimer(event:MouseEvent):void {
trace("stopTimer fired");
tTimer.stop();
}

function allActions(param:Number) {
trace("all actions fired");
if (param == 1) {
for (i=1; i<=numOfMenu; i++) {
root["slice"+i].bg.buttonMode = false;
root["slice"+i].bg.addEventListener(MouseEvent.MOUSE_OVER, setTimer);
root["slice"+i].bg.addEventListener(MouseEvent.MOUSE_OUT, stopTimer);
root["slice"+i].addEventListener(Event.ENTER_FRAME, Enter);
}
trace("MainMovieParam =" + param);
mainEnterTimer();
} else {
trace("stopped");
mainEnterTimerStop();
}// end if
};



Thanks in advance for any help!

Timers, Fps, Intervals And A Partridge In A Peartree.
Ok here’s the thing. I have a flash game that uses a timer. I want the timer to be represented by a bar. I think I can pretty much figure everything out except how everything updates.

For example, let’s say my flash doc is set at 1000fps (huge I know but its easier for the example). That means it will update the screen every 1ms. So therefore if I set an interval function that decrements my time by .001 of a second every 1ms and draw my bar every frame, I will get a nice smooth bar. The thing that I can't get my head around is, if my fps is like 24, then isn't that going to mess up the sync between the time, (i know that I won't at the machine level, but visually won't it look stuttery?).

Is it a case that I should have a global 'update' interval function that does stuff every frame (e.g setInterval( function, 1000/24 ) for a 24 fps doc.). I think this might be the way to go but the more I think about it the more my head hurts.

As you can see I’ve got myself into a twist, is there anyone that can offer me a structured explanation as to the best way to implement a timer bar into a flash game? I don't necessarily need the code just the theory. Thanks in advance.

Copyright © 2005-08 www.BigResource.com, All rights reserved