The Sprite object is a basic display list building block: a display list node that can display graphics and can also contain children.

A Sprite object is similar to a movie clip (not supported), but does not have a timeline. Sprite is an appropriate base object for objects that do not require timelines. For example, Sprite would be a logical base object for user interface(UI) components that typically do not use the timeline.


Inherited from DisplayObjectContainer -> InteractiveObject -> DisplayObject -> EventDispatcher


Can be created with method new:

Lib.Media.Display.Sprite.new()

Creates a new Sprite instance. After you create the Sprite instance, call the DisplayObjectContainer.addChild() or DisplayObjectContainer.addChildAt() method to add the Sprite to a parent DisplayObjectContainer.



created Sprite has properties:

buttonMode

Specifies the button mode of this sprite. If true, this sprite behaves as a button, which means that it triggers the display of the hand cursor when the pointer passes over the sprite and can receive a click event if the enter or space keys are pressed when the sprite has focus. You can suppress the display of the hand cursor by setting the useHandCursor property to false, in which case the pointer is displayed.

Although it is better to use the SimpleButton object (not supported) to create buttons, you can use the buttonMode property to give a sprite some button-like functionality. To include a sprite in the tab order, set the tabEnabled property(inherited from the InteractiveObject class and false by default) to true. Additionally, consider whether you want the children of your sprite to be user input enabled. Most buttons do not enable user input interactivity for their child objects because it confuses the event flow. To disable user input interactivity for all child objects, you must set the mouseChildren property(inherited from the DisplayObjectContainer object) to false.

If you use the buttonMode property with the MovieClip object (not supported)(which is a subclass of the Sprite class), your button might have some added functionality.

useHandCursor

A Boolean value that indicates whether the pointing hand(hand cursor) appears when the pointer rolls over a sprite in which the buttonMode property is set to true. The default value of the useHandCursor property is true. If useHandCursor is set to true, the pointing hand used for buttons appears when the pointer rolls over a button sprite. If useHandCursor is false, the arrow pointer is used instead.

You can change the useHandCursor property at any time; the modified sprite immediately takes on the new cursor appearance.

Note: if your sprite has child sprites, you might want to set the mouseChildren property to false. For example, if you want a hand cursor to appear over a control, set the useHandCursor and buttonMode properties to true, and the mouseChildren property to false.


methods:

startDrag(lockCenter, bounds)

Lets the user drag the specified sprite. The sprite remains draggable until explicitly stopped through a call to the Sprite.stopDrag() method, or until another sprite is made draggable. Only one sprite is draggable at a time.

Three-dimensional display objects follow the pointer and Sprite.startDrag() moves the object within the three-dimensional plane defined by the display object. Or, if the display object is a two-dimensional object and the child of a three-dimensional object, the two-dimensional object moves within the three dimensional plane defined by the three-dimensional parent object.

lockCenter - Specifies whether the draggable sprite is locked to the center of the pointer position(true), or locked to the point where the user first clicked the sprite(false).

bounds - Value relative to the coordinates of the Sprite's parent that specify a constraint rectangle for the Sprite.

stopDrag()

Ends the startDrag() method. A sprite that was made draggable with the startDrag() method remains draggable until a stopDrag() method is added, or until another sprite becomes draggable. Only one sprite is draggable at a time.



Examples:


Sprite = Lib.Media.Display.Sprite

stage = Lib.Media.Display.stage


sprite = Sprite.new()

sprite.name = "Sprite 1"

sprite.graphics.lineStyle(2, 0x00FF00, 1.0, false, nil, nil, nil, 3)

sprite.graphics.beginFill(0xFFFF00, 1.0)

sprite.graphics.drawRect(0,0, 200, 100)

sprite.graphics.endFill()

sprite.buttonMode = true

stage.addChild(sprite)


sprite.x = 10

sprite.y = 10


sprite.addEventListener(Lib.Media.Events.MouseEvent.CLICK, 

function(e)

       print(e.target.name)

end, false, 0, false)

Created with the Personal Edition of HelpNDoc: Generate EPub eBooks with ease