Chapter 12. Animation

FLASH AND ANIMATION are almost synonymous. Although ActionScript gives Flash abilities that go far beyond simple animation, animators are still a key part of the audience for Flash. The software is used to create commercials, videos, and even television shows—such as Cartoon Network’s Emmy-Award-winning Foster’s Home for Imaginary Friends. AS2 brought animation to a new level with the undocumented Tween object, and things have only gotten better in AS3. This chapter covers the differences when creating Tween object instances and handling tween events in AS2 and AS3, and introduces the improvements in AS3.

Tweening

Scaling, fading in and out, rotating, or any simple animation can be accomplished with the Tween object. The functionality is essentially the same, but the ActionScript packages have been updated and the Tween object is officially documented in Flash help. This section takes a look at these updates.

AS2: Tweening

The following code is an example that builds on code in the previous chapter. The custom drawCircle method creates a MovieClip, then the Tween object animates the circle horizontally across the stage. The Tween object creates an animation based on seven parameters: the item being animated; the property that you want to effect, such as the _x or _y axis; the easing method; start position; end position; time; and finally, a Boolean to determine whether to use seconds or the timeline as the timing mechanism.

Figure . 

AS3: Tweening

As mentioned earlier, the Tween object is essentially the same in ActionScript 3, but now it is officially documented and the class paths have been updated. Another difference is some of the properties that you will use as parameters—such as x, y, xscale, yscale, and rotation—no longer use the underscore.

AS3: Tweening

Events

Events drive what occurs in a Flash movie, and the Tween object is no exception to the new event-handling model. The old callback-function properties from the Tween class in ActionScript 2 have been updated to a new event object that is designed for the Tween class in AS3.

AS2: Events

Event handling is the life force in Flash, and the Tween object has five events that can trigger custom functionality—start, stop, resume, finish, and even a change in the Tween object. The TweenExample shows how two different callback-function properties from the Tween object can fire custom class methods when they occur.

Figure . 

AS3: Events

ActionScript 3 takes a more orderly approach to events with the new TweenEvent class. The TweenEvent class contains static properties that represent the events that can occur with a Tween object instance. The same events are available with the updated Tween class, but are now stored in the handy TweenEvent class.

The next example shows how listeners are added to a Tween instance in order to dispatch an event when the animation has changed or finished. When an event is fired from the TweenEvent class, it can easily call a custom class method. The method receives a parameter value that is a TweenEvent and provides details about the event when it occurs.

AS3: Events
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.130.201