The SWF::Sprite (or SWF::MovieClip) Module

The SWF specification defines an object called a Sprite, an encapsulated movie with its own timeline that can be added to another movie’s timeline. The sprite plays concurrently with any other objects or MovieClips on the main timeline. Flash users may be more familiar with the term MovieClip; you can use the alias SWF::MovieClip for a sprite if you want to.

The behavior of SWF::Sprite methods is identical to that of the methods described for the SWF::Movie object. The following methods may be called on a sprite:

new( )
add( )
remove( )
nextFrame( )
setFrames( )
labelFrame( )

Remember that the add() method returns a DisplayItem that refers to the object on the sprite’s timeline, not on the parent movie’s timeline. See the Astral Trespassers script at the beginning of this chapter for an example of an application using multiple sprites.

Several ActionScript commands operate on sprites, but ActionScript uses the term MovieClip instead of sprite. For example, the duplicateMovieClip( ) ActionScript method can be applied to a sprite to create a new copy of itself. See Appendix D for a complete ActionScript command reference.

Get Perl Graphics Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.