Sprites and Movie Clips

Sprites and Movie Clips Contents

Sprites and Movie Clips Contents........................................................................... 1

Sprites and Movie Clips.............................................................................................. 1

Sprite Names................................................................................................................... 1

DefineSprite................................................................................................................... 2

QuickTimeä Movies...................................................................................................... 3

 

Sprites and Movie Clips

A sprite corresponds to a ‘movie clip’ in the Flash user-interface.  It is a SWF movie contained within a SWF movie, and supports many of the features of a regular Flash movie, including:

 

·       Most of the control tags that can be used in the main movie.

·       A timeline that can stop, start and play independently of the main movie.

·       A streaming sound track that is automatically mixed with the main sound track.

 

A sprite object is defined with a DefineSprite tag.  It consists of a character ID, a frame count, and a series of control tags.  Definition tags (such as DefineShape) are not allowed in the DefineSprite tag.  All the characters referred to by control tags in the sprite must be defined outside the sprite, and before the DefineSprite tag.

 

Once defined, a sprite is displayed with a PlaceObject2 tag in the main movie.  The transform (specified in PlaceObject) is concatenated with the transforms of objects placed inside the sprite.  These objects behave like ‘children’ of the sprite, so when the sprite is moved, the objects inside the sprite move also.  Similarly, when the sprite is scaled or rotated, the child objects are also scaled or rotated.  A sprite object stops playing automatically when it is removed from the display list.

Sprite Names

When a sprite is placed on the display list, it can be given a name with the PlaceObject2 tag.  This name corresponds to the instance name in the Flash user-interface.  It is used to identify the sprite so the main movie (or other sprites) can perform actions inside the sprite.  This is achieved with the SetTarget action (called ‘Tell Target’ in the Flash user-interface)

 

For example, say a sprite object was placed in the main movie with the name “spinner”.  The main movie can send this sprite to the first frame in its timeline with the following action sequence:

 

1.     SetTarget “spinner”

2.     GotoFrame zero

3.     SetTarget “” (empty string)

4.     End of actions. (Action code = 0)

 

Note: All actions following SetTarget “spinner” apply to the spinner object until SetTarget “”, which sets the action context back to the main movie.

 

SWF supports placing sprites within sprites, which can lead to complex hierarchies objects.  To handle this complexity SWF uses a naming convention similar to that used by file systems to identify sprites.

 

For example, the following outline shows four sprites defined within the main movie:

 

MainMovie.swf

    SpriteA (name: Jack)

          SpriteA1 (name: Bert)

          SpriteA2 (name: Ernie)

    SpriteB (name: Jill)

 

The following  SetTarget paths identify the sprites above:

 

·       /Jack  targets SpriteA from the main movie.

·       ../ targets the main movie from SpriteA

·       /Jack/Bert targets SpriteA1 from any other sprite or the main movie.

·       Bert targets SpriteA1 from SpriteA.

·       ../Ernie targets SpriteA2 from SpriteA1

·       ../../Jill targets SpriteB from SpriteA1

 

DefineSprite

The DefineSprite tag defines a sprite character.  It consists of a character ID and a frame count, followed by a series of control tags.   The sprite is terminated with an End tag.

 

Definition tags (such as DefineShape) are not allowed in the DefineSprite tag.  All the characters referred to by control tags in the sprite must be defined in the main body of the file before the sprite is defined.

 

(See class FDTSprite in the Flash File Format SDK)

 

DefineSprite

Field

Type

Comment

Header

RECORDHEADER

Tag ID = 39

Sprite ID

UI16

ID of sprite

FrameCount

UI16

Number of frames in Sprite.

ControlTags

 TAG[one or more]

A series of tags

 

The valid tags within a DefineSprite tag are as follows:

·       ShowFrame

·       PlaceObject

·       PlaceObject2

·       RemoveObject

·       RemoveObject2

·       DoAction

·       StartSound

·       FrameLabel

·       SoundStreamHead

·       SoundStreamBlock

·       End

 

QuickTimeä Movies

A QuickTime movie is defined with the DefineMovie tag.  It is defined using an external reference to a file or URL.  A movie character can be placed on the Display List like any other character.

 

DefineMovie

Field

Type

Comment

Header

RECORDHEADER

Tag ID = 38

MovieID

UI16

ID of Movie

MovieName

STRING

Filename or URL of the movie.