5 Replies Latest reply on Mar 25, 2007 12:07 PM by Greg Dove

    Actionscripting Required

    dmc99
      Hi,

      I have a movie clip at 15 fps containing clouds that tween from frame 1-843 (inside the clip) to give them a slow moving effect. I've placed the mc on frame 1 of my main timeline. The clouds are moving jagged like across my main timeline consisting of 925 frames. Is there actionscripting that can make this move smoother and if so, would I change the movie clip to a graphic, keep in frame 1 of main timeline and use scripting? If so, what would the actionscripting be? Any tips would be greatly appreciated in smoothing out animation - Also I'd prefer not to increase my fps to 30 as there are other animated buttons that operate at 15 on this same page so I can't change the fps.

      Thank you.
        • 1. Re: Actionscripting Required
          kglad Adobe Community Professional & MVP
          if you use actionscript to tween your clouds, you'll lose your timeline tweening.

          to use actionscript for slow movement you should "tween" a variable's value and assign your clouds _x property the variable's value.
          • 2. Actionscripting Required
            Greg Dove Level 4
            I googled it... I think this is what you want..

            http://www.flashvalley.com/fv_tutorials/updateAfterEvent/page2.php

            Well its not exactly what you want but I think it will be a good starting point. Instead a the green sphere, you would be moving your clouds _x and _y properties as per kglads comment.
            • 3. Re: Actionscripting Required
              dmc99 Level 1
              Can you explain that in greater detail? I gather I'd remove the tween inside the movie clip?

              thks.
              • 4. Re: Actionscripting Required
                Greg Dove Level 4
                The issue is that your frame rate is at 15 fps and you don't want to change it for the reasons you explained.

                The solution is that yes, you will need to change your clouds _x and _y properties with actionscript to make things move more smoothly, but that alone won't fix things, because even if you do this with actionscript, flash still only updates the screen at 15 fps.

                So the link I posted gave and example not only of moving something in actionscript, but forcing screen updates more frequently than the _root timeline framerate in order to make the animation appear smoother. This example is the movie 2 code on that page with the updateAfterEvent() function - there are only a couple of ways you can use it and the setInterval function call is one of them. What it does essentially is just force flash rendering of the current frame more often. So it shouldn't affect your other items which are intended to play at 15 fps.

                I think (using the code 2 example from that page) you want something like this (where what you call your clouds is an instance of a 'movieclip' symbol.. not a 'graphic' in the properties panel... and is named myClouds:

                setInterval(moveClouds, 32); //close to simulated 30 fps for update calls.

                // this is our main function that will animate the clouds
                function moveClouds() {
                myClouds._x += 0.5 //whatever _x increment you want each 32ms.

                // here we refresh the screen each time the function is called, in our case every 32ms
                updateAfterEvent();
                }

                This is OK as is if setInterval only ever gets called once and you want the clouds to keep moving. You need to be careful that you don't call setInterval in any situation repeatedly without tracking it and cancelling appropriately. You also may want to check if myClouds._x is >= to a certain value inside the moveClouds function and reset its _x value back to the start postion if you want it to "loop".
                If you need to tween _y, then just do the same as for _x in the code, but change the 0.5 to whatever makes sense.
                If you ever need to stop the clouds moving or the setInterval code might get called repeatedly then you should take the return value from the setInterval function and assign it to a variable to use with clearInterval (which cancels that particular setInterval):

                var myCloudInterval =setInterval(moveClouds, 32); //close to simulated 30 fps for update calls


                later on if you use:

                clearInterval(myCloudInterval) ;

                It will stop the extra screen updates and the cloud animation. If you want the speed to vary at different points including the ability to stop the clip is to try changing the 0.5 in the function above to a variable that exists outside the function and changing that outside the function (e.g. a value of zero would mean no movement)...lots of possibilities. Good Luck.
                • 5. Re: Actionscripting Required
                  Greg Dove Level 4
                  And yes, (finally, I hear you say) you remove the tween inside the movie clip... all it needs to be is basically just a still image of the clouds. One frame.