|
-
Stopping countup timer on hitTest?
Hey everyone,
I am working on a project for school which involves developing a timer that counts up to accompany a small game.
My idea involves the timer recording the amount of time taken to complete a small level, and then displaying the
stopped time on the next frame as a final score.
This is the code I used for the countup timer (I am using AS2):
timer = 0;
countup = function() {
timer++;
}
countupInterval = setInterval(countup,1000);
What I want to happen is for the counter to stop once the player reaches a certain object. The hitTest is already
set up on the movie clip of the goal object, using this code (placed on the movie clip):
onClipEvent (enterFrame) {
if (this.hitTest (_root.player)) {
_root.gotoAndStop (2);
}
}
What I cant seem to be able to do is create code that will stop the timer once the player moves over the hitTest,
allowing it to be displayed as a final score on the second frame. I have been researching on many forums and tutorial
sites and have not yet found code so far that works for me in this situation. The project is due a week from now, if
you guys could help me it would be much appreciated ! I can also provide any other additional details that may be needed.
p.s: I am using Flash CS5
-
Senior Member
Use clearInterval(countupInterval); to stop the count, then display timer variable in a dynamic text field.
-
I've tried that before, but it doesnt seem to work.
Where should I put the code, so that it works ? I'm pretty new to actionscript haha
-
Senior Member
Um.. pretty straight-forward, place the stop code where you want it to occur... after hitTest, i'm guessing.
-
Designer, Programmer, Musician
I think you have an onEnterFrame holding the interval function, even if you clear the interval, the function will keep executing. You have to delete the onEnterFrame
Actionscript Code:
delete this.onEnterFrame;
Hope that helps
 Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|