Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-10-2012, 11:35 PM   #1
BoyWonder1911
Registered User
 
Join Date: Jun 2012
Posts: 6
Default Problem with Timer

So I have a timer in game. When you swat 10 mosquitos, I have it set to where the timer resets, and goes back to 45. Then you have to swat 15, then 20, etc etc
If you run out of time, then it's supposed to make a buzzing sound.
ActionScript Code:
if (_timer.currentCount == 0) {_buzz.play();}

but for some reason, every time I
ActionScript Code:
_timer.reset();
when I hit 10 mosquitos, or 15, or whatever level I'm on, it plays the buzz sound clip.

How do I bypass the timer from resetting to 0 first, then 45?

The timer is set in a text field that displays the timer counting down.

Thanks!
BoyWonder1911 is offline   Reply With Quote
Old 06-11-2012, 11:38 AM   #2
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

You won't get far with only that code, post more contextual code!
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 06-12-2012, 12:18 AM   #3
BoyWonder1911
Registered User
 
Join Date: Jun 2012
Posts: 6
Default

Did you try reading my question?
I don't need you to know my code, only need to know how to bypass the timer resetting to 0 before going back to where I have it set at 45.
BoyWonder1911 is offline   Reply With Quote
Old 06-12-2012, 07:24 AM   #4
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

Oh, this is Actionscript 3.0, I thought it was AS2, so I thought timer() was a function you had manually defined. I'll try to fix your problem later (I'm on a different computer, one which does not have Flash with AS3)
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 06-12-2012, 06:14 PM   #5
rynoe
Member
 
rynoe's Avatar
 
Join Date: Feb 2003
Posts: 57
Default

Can you add an event listener?

myTimer.addEventListener(TimerEvent.TIMER_COMPLETE , buzz)
rynoe is offline   Reply With Quote
Old 06-12-2012, 08:27 PM   #6
BoyWonder1911
Registered User
 
Join Date: Jun 2012
Posts: 6
Default

I ended up altering my code here, to update on ENTER_FRAME along with my score update.

when the _timerText.text == 0, then the _buzz.play(); works, and it doesn't play when the timer resets, so that is what I wanted.

But now, I have another problem. The _buzz soundclip plays every frame, 30 times a second. I don't know how to stop it other closing the window.

ActionScript Code:
public function updateScore(evt:Event):void     {         _scoreText.text = String(_points);         _timerText.text = String((_timerNum) - _timer.currentCount);                 if (_timerText.text == "0")                     {                         _buzz.play();                                                 _timer.stop();                                          }         }
BoyWonder1911 is offline   Reply With Quote
Old 06-14-2012, 03:42 PM   #7
adaminaudio
Member
 
Join Date: Jan 2012
Posts: 62
Default

hi there,

so couldn't you do what Rynoe said as opposed to putting it onto your enter frame? because every time you enter the frame (30fps), your currentcount is 0 and since your condition is met then the sound will play.

so maybe try what Rynoe said:

ActionScript Code:
var timer = new Timer(45000,1); timer.addEventListener(TimerEvent.TIMER, timerHandler); timer.addEventListener(TimerEvent.COMPLETE, onTimerComplete); timer.start(); ... private function timerHandler(event:TimerEvent):void {        //do whatever you need when the timer is ticking down } private function onTimerComplete(event:TimerEvent):void {       //timer has stopped, no need to track a variable...       buzz.play(); }

of course, I could be totally misunderstanding what you're trying to do. If so I do apologize

v/r

-Adam

Last edited by adaminaudio; 06-14-2012 at 03:43 PM. Reason: change
adaminaudio is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:05 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.