BeginSprite

From Director Online Wiki
Jump to: navigation, search

An event that is sent to a sprite on creation. That is, during playback, the first time that the playhead lands on a frame having a given sprite in the score, that sprite will receive this event.

Jumping to another frame does not trigger this event so long as both the originating and target frames are within the same sprite span.

This event is the usual place to set up useful default properties within a behavior. Some of these are particularly common and will be seen in almost all behaviors, for example:

   property pSprite -- Instance of the current sprite
   on beginSprite( me )
     pSprite = sprite( me.spriteNum )
   end

This is very common because saving a copy of the sprite in a property saves writing sprite( me.spriteNum ) all the time. It is also more efficient, because dereferencing the sprite in this way all the time is slow.

If your behavior contains an on new() handler, then this will be called before the beginSprite handler. All behaviors on a sprite will receive a #new event before any of the sprites receive a #beginSprite event. Any behavior properties set in a getPropertyDescriptionList() handler will be available to the beginSprite handler, but not to a new() handler.

Behaviors created on the fly

If you dynamically (that is, during the runtime) attach a behavior to a sprite, then the beginSprite handler, will not be triggered. Remember, to call the handler manually, issuing something like:

sprite(n).beginSprite()

See: Creating Behaviors on the Fly