11 Replies Latest reply on Mar 6, 2009 4:16 AM by Ned Murphy

    how do I delay a loop?

    FlashTapper Level 1
      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
        • 1. Re: how do I delay a loop?
          Ned Murphy Adobe Community Professional & MVP
          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.
          • 2. Re: how do I delay a loop?
            FlashTapper Level 1
            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...
            • 3. Re: how do I delay a loop?
              Ned Murphy Adobe Community Professional & MVP
              It is really quite simple and in a minute or so I'll have an example you can download.
              • 4. how do I delay a loop?
                Ned Murphy Adobe Community Professional & MVP
                Here you go: ScrollTimeLine

                Let me know if you need a Flash 8 version of it. This one's CS3
                • 5. how do I delay a loop?
                  Ned Murphy Adobe Community Professional & MVP
                  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;
                  • 6. Re: how do I delay a loop?
                    FlashTapper Level 1
                    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!
                    • 7. Re: how do I delay a loop?
                      FlashTapper Level 1
                      Sorry...just another small question. There is now way to lock it so that it does not scroll anymore once the end of the timeline moves through the screen?

                      Ryan
                      • 8. Re: how do I delay a loop?
                        Ned Murphy Adobe Community Professional & MVP
                        To slow it down, you adjust the values in the enter frame equation. I didn't use any special reasoning in setting them--just something to avoid jumping too much distance in a step. Try tweaking that value of 100 at the end. Also, the speed is dictated by the distance of the mouse from center stage, so if you made two buttons and made them smaller and moved them, how fast thiings go depend on how far they are from center stage. Up your frame rate to get nice smooth movement and adjust the equation.

                        As far as stopping at the ends goes, some conditional logic will need to be added based on mouse position and mc position. It may require some changes to the coding approach.
                        • 9. Re: how do I delay a loop?
                          Ned Murphy Adobe Community Professional & MVP
                          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.
                          • 10. Re: how do I delay a loop?
                            FlashTapper Level 1
                            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!
                            • 11. Re: how do I delay a loop?
                              Ned Murphy Adobe Community Professional & MVP
                              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.