Timer

  • IH8Purple
  • Guru
  • Guru
  • User avatar
  • Posts: 1215
  • Loc: Somewhere on Google Earth

Post 3+ Months Ago

Currently I am trying to use an object s a timer,
I used thefollowing actionscript:
Code: [ Select ]
onClipEvent (enterFrame) {
    //generating movement
    location = this._x;
    var i;
    i = 1;
    if (this, hitTest(_root.time)) {
        [b]gotoAndPlay(3)[/b]
    } else {
        this._x = location+i++;
    }
  1. onClipEvent (enterFrame) {
  2.     //generating movement
  3.     location = this._x;
  4.     var i;
  5.     i = 1;
  6.     if (this, hitTest(_root.time)) {
  7.         [b]gotoAndPlay(3)[/b]
  8.     } else {
  9.         this._x = location+i++;
  10.     }


the code:
Code: [ Select ]
gotoAndPlay(3)

it will go to frame 3 of the movie clip, not frame 3 of scene 1. and I want it to go to frame 3 of scene 1


BTW: if there is another way to set a timer I will accept that instead
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

What kind of timer are you going for?

I'm not exactly sure what you are trying to do.

You may want to look into getTimer() though. Either that or setInterval().
  • IH8Purple
  • Guru
  • Guru
  • User avatar
  • Posts: 1215
  • Loc: Somewhere on Google Earth

Post 3+ Months Ago

umm basically I have a gmae and so far it is set up like this

Frame 1 = instructions and play button
Frame 2 = actual Game
Frame 3 = Score screen (end of game)

what I want is that after a certain time the player goes from frame 2 to frame 3
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

On frame one add these actions
Code: [ Select ]
//stop playing the timeline
stop();
//define variable for what frame to be on (frame 1 by default)
var frame = 1;
//create function to be called using setInterval
function goNextFrame(){
//increment frame variable by 1
frame++;
//go to and stop at frame#
gotoAndStop(frame)
//if the frame is equal to 3
if (frame == 3){
//stop running the setInterval
clearInterval(timer);
}
}
//create setInterval
timer = setInterval(goNextFrame, 5000);
  1. //stop playing the timeline
  2. stop();
  3. //define variable for what frame to be on (frame 1 by default)
  4. var frame = 1;
  5. //create function to be called using setInterval
  6. function goNextFrame(){
  7. //increment frame variable by 1
  8. frame++;
  9. //go to and stop at frame#
  10. gotoAndStop(frame)
  11. //if the frame is equal to 3
  12. if (frame == 3){
  13. //stop running the setInterval
  14. clearInterval(timer);
  15. }
  16. }
  17. //create setInterval
  18. timer = setInterval(goNextFrame, 5000);


Now setInterval works like this..


setInterval(functionToCall, howOftenToCallIt)

How often you call it is in milliseconds, so 1000 milliseconds = 1 second thus the script above calls the goNextFrame function every 5 seconds, so the frames will change after 5 seconds (I just typed in a random value)
  • IH8Purple
  • Guru
  • Guru
  • User avatar
  • Posts: 1215
  • Loc: Somewhere on Google Earth

Post 3+ Months Ago

it works, TY lostinbeta
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Woo hoo! Usually my untested code never works!

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 17 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.