|
|
|
#1 |
|
Member
Join Date: Oct 2002
Location: Tucson
Posts: 92
|
another stupid timer question...sorry
I know I know...I've looked at 30 posts on this and still can't get it to do what I want. Sorry for posting it again, but I've been beating myself over the head, and I have to get this done.
Now, I have a MC on stage named Fred. Fred has 4 frames. I want to change to a random frame in fred every 5 seconds. Fred has a stop() in his first frame. Here's what I have placed on fred: onClipEvent(load) { fred.gotoAndStop(random(4)+1); delay = 5000; // a 5 second delay resetTime = getTimer() + delay; } onClipEvent(enterFrame) { if (getTimer() > resetTime) { gotoAndStop(random(4)+1); } } When the movie starts fred waits 5 seconds then he just starts flippin through his 4 frames. Anybody? Thanks, -Lemorris |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
|
You've nearly got it, you just need to reset the timer whenever you you've determined it's time to jump frames, like so:
Modifying your original code: (I wasn't sure what 'fred' was - if it's the clip this code is attached to, you don't need it).
Here's a shorter rewrite:
Here's a more concise method that uses setInterval. Should be less of a drain on the CPU since you're not using an enterFrame handler.
- Jim |
|
|
|
|
|
#3 |
|
Member
Join Date: Oct 2002
Location: Tucson
Posts: 92
|
Great Scott Jim!!
Who are you?!! Thanks much for the speedy reply. You pulled my hinder out of the fire again. -Lemorris |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Apr 2006
Posts: 11
|
tried #3 (setInterval) without success
Hi,
wondering if anyone has insights into the 3rd approach, with which I got a very different effect than with the other 2. I've been trying to understand setInterval better so I was happy to see Jim was giving an example. I've read some of his posts on other stuff, & looked at KrazyDad - all great. I'm not having any luck, though, with the setInterval example. I'm copying and pasting it to a mc containing 5 different frames - the same mc that works with the other approaches. With the setInterval approach, it races randomly through the frames for 5 seconds.... Wondering if anyone can explain how to make setInterval behave the same as the other 2. I'm imagining it will give me a better understanding of what's going on than even just seeing a working one. cs |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|