4.15. Animating Runtime Location Changes with ActionScript
Problem
You want to animate using ActionScript.
Solution
Use the mx.transitions.Tween class.
Discussion
All forms of animation discussed thus far in the chapter are created at authoring time and are effectively hardcoded. After playback begins, the animations can play back only in the way that you specified at authoring time. Because they are hardcoded in this way, these kinds of animation cannot respond to the user.
You may want to create animations that respond to user activity. For example, you may want to make an object move to the location of the mouse when the user clicks it. You must use ActionScript if you want to make such an animation.
There are several ways in which you can approach animating objects with Action-Script, but each has the same basic principle—updating the values of the property or properties over time. It’s possible to use event handler methods such as onEnterFrame( ) or to use an interval function with setInterval( ) to accomplish the task. However, both of those approaches are slightly more complex (and require more ActionScript) than using the mx.transitions.Tween class to accomplish the task.
The mx.transitions.Tween class enables you to animate a change in a property with just one line of code. However, to make referencing the class a little simpler, it’s generally recommended that you first use an import statement. The following line of code tells Flash to look for the Tween class in a package called ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access