Skip to main content
FlashTapper
Inspiring
March 6, 2009
Answered

how do I delay a loop?

  • March 6, 2009
  • 5 replies
  • 739 views
I am trying to build a timeline whereby a user moves his/her mouse across the screen and the timeline moves to the right or left accordingly. I am doing this in a bit of a "dirty" fashion because I am short for time and expertise. Instead of creating a completlely dynamic component to handle this (or whatever complicated method) - I have just got 3 sets of vertical invisible buttons on either side that are supposed to scroll at different speeds (i.e. myMovie_mc._x++ / myMovie_mc._x+=3, etc.

I trying to execute this by using the "While" loop whilst the user has enabled a button rollover (the invisble vertical buttons). Problem is - loops are almost instantaneous! There is no scrolling, it just jumps to the beginning or end.
I have tried using setInterval method inside the loop itself but it does not work and seems to crash the flash player (no surprise there!). Is there any other easy way I can delay a loop so the user can at least see the timeline moving across the screen?

Thank you in advance.

Ryan
This topic has been closed for replies.
Correct answer FlashTapper
For stopping at the ends, since you're using two buttons, which I'll assume are for different scrolling directions, placing them appropriately on opposite sides of the stage takes care of the mouse conditionals that would otherwise be needed. The code would change to what I've attached below... hopefully you can adapt it into what I already provided.
Thanks again Ned. It worked perfectly. Now I am able to speed up my frame playback and get some smooth animation. Also the stopping at the ends re-adjustment to the code worked without a hitch (just needs a fine tune).
Now I can do all the fun stuff like importing XML feeds!

5 replies

Ned Murphy
Legend
March 6, 2009
You're welcome. Hopefully you've learned something and have a new tool or two under your belt.

Just remember, the button positions relative to center stage also play a role in the speed--only because of the initial design approach of using mouse position. It could have been done differently, relative only to the buttons themselves.

I don't normally hand out complete solutions. In your case it, as simple as it is, I've never done it before and wanted to solve it for myself.
Ned Murphy
Legend
March 6, 2009
I utilized a button to control the scrolling so that the timeline would be free for having mouse-able items on it. If you don't plan to have any mouse-able items in the timeline, you can just replace the "btn" in the script to be "mc" and hovering the timeline will make it move.

One thing I neglected to do that should be done is to declare the variable that gets used...

var moveIt = false;
FlashTapper
Inspiring
March 6, 2009
Thanks for that! I have CS3 so it is all good. Actually cut the button into two so that the whole stage would not be covered (I plan to have people clicking on buttons within the timeline and it may cause them to stress out if it constantly moves). It's simple and I like it, thanks Ned.

From what I can see, the only way to slow the movement down is to lower the frame rate that the movie plays at (I lowered it to 8 frames per second, it's a little jumpy - is there any other way you can slow it down? I think it really only got faster because I made two shorter buttons calling the same script that sit on the left and right of the stage.
Other than that, fantastic solution!
Ned Murphy
Legend
March 6, 2009
Here you go: ScrollTimeLine

Let me know if you need a Flash 8 version of it. This one's CS3
Ned Murphy
Legend
March 6, 2009
It is really quite simple and in a minute or so I'll have an example you can download.
Ned Murphy
Legend
March 6, 2009
There is no way you can delay a loop (that I know of). You'd be better off utilizing an enter frame event and basing the speed of movement on the mouse position relative to the center of the visible timeline/stage.
FlashTapper
Inspiring
March 6, 2009
Thanks for the quick reply. I thought that was the case (my searches on the internet did not look hopeful).
Have you got any pointers or directions on how to do it with the "enterFrame" method? It does sound a bit complex. Any help would be appreciated...