One of my current assignments at work is to make something similar to Google Maps for my employer’s Oil website. I must build a map browser that is completely dynamic that will need to generate 3 dynamic layers for 3 different types of maps of Oil Wells.
I decided on making this using Flash, just like Yahoo Maps have. From the start, the most important feature was how I had to permit a click event somewhere on the map and to center the map on these X and Y coordinates. At first, I approached the project by planning on incrementing a value to the _x and _y properties of the map MovieClip for some period of time to mimic movement until the map was re-centered, but I’ve had no success doing so.
That’s when I had a revelation. Once you start trying to build Object-Oriented applications in Flash, you tend to forget all the design tools built-in Flash. Why didn’t I call the Tween function from within ActionScript? And so I did.
Here’s the relatively simple function call to move a MovieClip object using the Tween class:
new mx.transitions.Tween(MovieClip, "_x", easeType, begin, end, speed of execution, time unit boolean);
You pass on a MovieClip, the property you wish to edit (in Flash, the properties all start with “_”), the effect you wish to use for the transition, the starting value (for the _x property, MovieClip ._x for instance), the end value (passing MovieClip ._x + 50 would create a motion tween that would move the MovieClip 50 pixels to the right from its original location), and the speed of execution which is either counted in seconds or in frames depending on the last Boolean parameter (true meaning seconds).
It’s really flexible and powerful. Passing in a different easing type will allow you to apply built-in elastic or bouncing effects to a MovieClip. Now all of the bouncing menus we see all over the Internet seem much simpler.
You can also pause, rewind and do other operations on the Tween process because it generates events as the animation plays.
It opens a lot of doors to OOP in Flash. You no longer need to bother with sketchy animations when forcing movement on your MovieClips from within a Class.
If you code in Flash and have never come across this function, I strongly suggest you read more on this undocumented function.
Comments
You can leave a response, or trackback from your own site. No Responses to “mx.transitions.Tween”.
Leave a Reply