MovieClip

public class
loom2d.display.MovieClip

Description

A MovieClip is a simple way to display an animation depicted by a list of textures.

Pass the frames of the movie in a vector of textures to the constructor. The movie clip will have the width and height of the first frame. If you group your frames with the help of a texture atlas (which is recommended), use the getTextures-method of the atlas to receive the textures in the correct (alphabetic) order.

You can specify the desired framerate via the constructor. You can, however, manually give each frame a custom duration. You can also play a sound whenever a certain frame appears.

The methods play and pause control playback of the movie. You will receive an event of type Event.MovieCompleted when the movie finished playback. If the movie is looping, the event is dispatched once per loop.

As any animated object, a movie clip has to be added to a juggler (or have its advanceTime method called regularly) to run. The movie will dispatch an event of type "Event.COMPLETE" whenever it has displayed its last frame.

See also:
loom2d.textures.TextureAtlas

API overview

Constructor

MovieClip ( textures: Vector.<Texture> , fps: Number = 12 )
Creates a movie clip from the provided textures and with the specified default framerate

Attributes

Public attributes

currentFrame: Number

The index of the frame that is currently displayed

currentTime: Number read-only

The time that has passed since the clip was started (each loop starts at zero)

fps: Number

The default number of frames per second

isComplete: Boolean read-only

Indicates if a (non-looping) movie has come to its end

isPlaying: Boolean read-only

Indicates if the clip is still playing

loop: Boolean

Indicates if the clip should loop

numFrames: Number read-only

The total number of frames

totalTime: Number read-only

The total duration of the clip in seconds

Protected attributes

Functions

Public functions

addFrame ( texture: Texture , sound: String = null , duration: Number = ): Void

Adds an additional frame, optionally with a sound and a custom duration

addFrameAt ( frameID: Number , texture: Texture , sound: String = null , duration: Number = ): Void

Adds a frame at a certain index, optionally with a sound and a custom duration

advanceTime ( passedTime: Number ): Void

Advance the time by a number of seconds

fromSpritesheet ( texturePath: String , cellWidth: Number , cellHeight: Number , totalNumCells: Number , numColumns: Number , fps: Number , juggler: Juggler = null ): MovieClip static

Static wrapper to help create a new MovieClip from a texture spritesheet path and some parameters

getFrameDuration ( frameID: Number ): Number

Returns the duration of a certain frame (in seconds)

getFrameSound ( frameID: Number ): String

Returns the sound of a certain frame

getFrameTexture ( frameID: Number ): Texture

Returns the texture of a certain frame

pause (): Void

Pauses playback

play (): Void

Starts playback

removeFrameAt ( frameID: Number ): Void

Removes the frame at a certain ID

setFrameDuration ( frameID: Number , duration: Number ): Void

Sets the duration of a certain frame (in seconds)

setFrameSound ( frameID: Number , sound: String ): Void

Sets the sound of a certain frame

setFrameTexture ( frameID: Number , texture: Texture ): Void

Sets the texture of a certain frame

stop (): Void

Stops playback, resetting "currentFrame" to zero

Protected functions

Constructor

MovieClip ( textures: Vector.<Texture> , fps: Number = 12 )

Creates a movie clip from the provided textures and with the specified default framerate. The movie will have the size of the first frame.

Attributes

alpha: Number
Inherited from DisplayObject

The opacity of the object, 0 = transparent, 1 = opaque.

b: Number
Inherited from Quad

Set blue color (0-255); convenience method for tweening.

base: DisplayObject
Inherited from DisplayObject

read-only

The topmost object in the display tree the object is part of.

blendEnabled: Boolean
Inherited from DisplayObject

Enables or disables blending. If set to false, there will be no blending and there may be performance gains.

blendMode: BlendMode
Inherited from DisplayObject
The default value is BlendMode.AUTO

The blend mode determines how the object is blended with the objects underneath.

See also:
loom2d.display.BlendMode

bounds: Rectangle
Inherited from DisplayObject

read-only

The bounds of the object relative to the local coordinates of the parent.

cacheAsBitmap: Boolean
Inherited from DisplayObject

If true, the untransformed contents get cached into a texture at render time. The contents remain static until you turn off caching or use invalidateBitmapCache to update the cache manually.

color: Number
Inherited from Quad

Returns the color of the quad, or of vertex 0 if vertices have different colors.

currentFrame: Number

The index of the frame that is currently displayed.

currentTime: Number

read-only

The time that has passed since the clip was started (each loop starts at zero).

depth: Number
Inherited from DisplayObject

If depthSort is enabled on parent, this will be used to establish draw order. Higher values are drawn closer. Matching values have undefined order.

fps: Number

The default number of frames per second. Individual frames can have different durations. If you change the fps, the durations of all frames will be scaled relatively to the previous value.

g: Number
Inherited from Quad

Set green color (0-255); convenience method for tweening.

hasVisibleArea: Boolean
Inherited from DisplayObject

read-only

Indicates if an object occupies any visible area. (Which is the case when its 'alpha', 'scaleX' and 'scaleY' values are not zero, and its 'visible' property is enabled.)

height: Number
Inherited from DisplayObject

The height of the object in pixels.

ignoreHitTestAlpha: Boolean
Inherited from DisplayObject

This can be used if you wish to have a DisplayObject with zero alpha still respond to hit tests

isComplete: Boolean

read-only

Indicates if a (non-looping) movie has come to its end.

isPlaying: Boolean

read-only

Indicates if the clip is still playing. Returns false when the end is reached.

loop: Boolean

Indicates if the clip should loop.

name: String
Inherited from DisplayObject

The name of the display object (default: null). Used by 'getChildByName()' of display object containers.

numFrames: Number

read-only

The total number of frames.

parent: DisplayObjectContainer
Inherited from DisplayObject

pivotX: Number
Inherited from DisplayObject

The x coordinate of the object's origin in its own coordinate space (default: 0).

pivotY: Number
Inherited from DisplayObject

The y coordinate of the object's origin in its own coordinate space (default: 0).

premultipliedAlpha: Boolean
Inherited from Quad

read-only

Indicates if the rgb values are stored premultiplied with the alpha value; this can affect the rendering. (Most developers don't have to care, though.)

r: Number
Inherited from Quad

Set red color (0-255); convenience method for tweening.

root: DisplayObject
Inherited from DisplayObject

read-only

The root object the display object is connected to (ie: an instance of the class that was passed to the Starling constructor), or null if the object is not connected to the stage.

rotation: Number
Inherited from DisplayObject

The rotation of the object in radians, (In Loom2D, all angles are measured in radians.)

scale: Number
Inherited from DisplayObject

General scale factor. '1' means no scale, negative values flip the object. Use this when setting scaleX/scaleY explicitly is too verbose.

scaleX: Number
Inherited from DisplayObject

The horizontal scale factor. '1' means no scale, negative values flip the object.

scaleY: Number
Inherited from DisplayObject

The vertical scale factor. '1' means no scale, negative values flip the object.

shader: Shader
Inherited from Quad

native

skewX: Number
Inherited from DisplayObject

The horizontal skew angle in radians.

skewY: Number
Inherited from DisplayObject

The vertical skew angle in radians.

smoothing: Boolean
Inherited from Image

True means linear filtering is applied to textures; false means point filtering is used.

source: String
Inherited from Image

write-only

stage: Stage
Inherited from DisplayObject

read-only

The stage the display object is connected to, or null if it is not connected to the stage.

styleName: String
Inherited from DisplayObject

The style name used by the CSS system.

texture: Texture
Inherited from Image

The texture that is displayed on the quad.

tinted: Boolean
Inherited from Quad

read-only

Returns true if the quad (or any of its vertices) is non-white or non-opaque.

totalTime: Number

read-only

The total duration of the clip in seconds.

touchable: Boolean
Inherited from DisplayObject

Indicates if this object (and its children) will receive touch events.

transformationMatrix: Matrix
Inherited from DisplayObject

The transformation matrix of the object relative to its parent.

If you assign a custom transformation matrix, Starling will try to figure out suitable values for x, y, scaleX, scaleY, and rotation. However, if the matrix was created in a different way, this might not be possible. In that case, Starling will apply the matrix, but not update the corresponding properties.

visible: Boolean
Inherited from DisplayObject

The visibility of the object, An invisible object will be untouchable.

width: Number
Inherited from DisplayObject

The width of the object in pixels.

x: Number
Inherited from DisplayObject

The x coordinate of the object relative to the local coordinates of the parent.

y: Number
Inherited from DisplayObject

The y coordinate of the object relative to the local coordinates of the parent.

Protected attributes

Functions

addEventListener ( type: String , listener: Function ): Void
Inherited from EventDispatcher

Registers an event listener at a certain object.

Parameters

type: String
listener: Function


addFrame ( texture: Texture , sound: String = null , duration: Number = ): Void

Adds an additional frame, optionally with a sound and a custom duration. If the duration is omitted, the default framerate is used (as specified in the constructor).

Parameters

texture: Texture
sound: String = null
duration: Number =


addFrameAt ( frameID: Number , texture: Texture , sound: String = null , duration: Number = ): Void

Adds a frame at a certain index, optionally with a sound and a custom duration.

Parameters

frameID: Number
texture: Texture
sound: String = null
duration: Number =


advanceTime ( passedTime: Number ): Void

Advance the time by a number of seconds.

Parameters

passedTime: Number


center (): Void
Inherited from DisplayObject

Center the DisplayObject's pivot point using the width and height. This centers this object about its own origin based on its width and height.



copyVertexDataTo ( targetData: VertexData , targetVertexID: Number = 0 ): Void
Inherited from Quad

Copies the raw vertex data to a VertexData instance.

Parameters

targetData: VertexData
targetVertexID: Number = 0


dispatchEvent ( event: Event ): Void
Inherited from EventDispatcher

Dispatches an event to all objects that have registered listeners for its type. If an event with enabled 'bubble' property is dispatched to a display object, it will travel up along the line of parents, until it either hits the root object or someone stops its propagation manually.

Parameters

event: Event


dispatchEventWith ( type: String , bubbles: Boolean = false , data: Object = null ): Void
Inherited from EventDispatcher

Dispatches an event with the given parameters to all objects that have registered listeners for the given type. The method uses an internal pool of event objects to avoid allocations.

Parameters

type: String
bubbles: Boolean = false
data: Object = null


dispose (): Void
Inherited from DisplayObject

Disposes all resources of the display object. GPU buffers are released, event listeners are removed, filters are disposed.



fromSpritesheet ( texturePath: String , cellWidth: Number , cellHeight: Number , totalNumCells: Number , numColumns: Number , fps: Number , juggler: Juggler = null ): MovieClip

static

Static wrapper to help create a new MovieClip from a texture spritesheet path and some parameters.

Parameters

texturePath: String Asset path for the texture spritesheet containing the frames to use
cellWidth: Number Width of each individual cell of animation
cellHeight: Number Height of each individual cell of animation
totalNumCells: Number Total number of cells in the spritesheet
numColumns: Number Number of columns of cells in the spritesheet
fps: Number Frames per second rate at which the MovieClip must play at
juggler: Juggler = null Juggler to add the MovieClip to if desired

Returns

MovieClip The newly created MovieClip object

getBounds ( targetSpace: DisplayObject , resultRect: Rectangle = null ): Rectangle
Inherited from DisplayObject

Returns a rectangle that completely encloses the object as it appears in another coordinate system. If you pass a 'resultRectangle', the result will be stored in this rectangle instead of creating a new object.

Parameters

targetSpace: DisplayObject
resultRect: Rectangle = null


getFrameDuration ( frameID: Number ): Number

Returns the duration of a certain frame (in seconds).

Parameters

frameID: Number


getFrameSound ( frameID: Number ): String

Returns the sound of a certain frame.

Parameters

frameID: Number


getFrameTexture ( frameID: Number ): Texture

Returns the texture of a certain frame.

Parameters

frameID: Number


getFullTypeName (): String
Inherited from Object

native

Gets the fully qualified type name of the Object. The fully qualified type name includes the package of the type.


Returns

String fully qualified type name of the Object.

getTargetTransformationMatrix ( targetSpace: DisplayObject , resultMatrix: Matrix ): Void
Inherited from DisplayObject

native

Parameters

targetSpace: DisplayObject
resultMatrix: Matrix


getTexCoords ( vertexID: Number ): Point
Inherited from Image

Gets the texture coordinates of a vertex. Coordinates are in the range [0, 1].

Parameters

vertexID: Number


getType (): Type
Inherited from Object

native

Gets the Type that describes the Object.


Returns

Type The Type that describes the object.

getTypeName (): String
Inherited from Object

native

Gets the type name of the Object.


Returns

String type name of the Object.

getVertexAlpha ( vertexID: Number ): Number
Inherited from Quad

Returns the alpha value of a vertex at a certain index.

Parameters

vertexID: Number


getVertexColor ( vertexID: Number ): Number
Inherited from Quad

Returns the color of a vertex at a certain index.

Parameters

vertexID: Number


getVertexPosition ( vertexID: Number ): Point
Inherited from Quad

Gets the position of a vertex at a certain index.

Parameters

vertexID: Number


getVertexTexCoords ( vertexID: Number ): Point
Inherited from Quad

Gets the texture coordinates of a vertex at a certain index.

Parameters

vertexID: Number


globalToLocal ( globalPoint: Point ): Point
Inherited from DisplayObject

Transforms a point from global (stage) coordinates to the local coordinate system.

Parameters

globalPoint: Point


hasEventListener ( type: String ): Boolean
Inherited from EventDispatcher

Returns if there are listeners registered for a certain event type.

Parameters

type: String


hitTest ( localPoint: Point , forTouch: Boolean = false ): DisplayObject
Inherited from DisplayObject

Returns the object that is found topmost beneath a point in local coordinates, or nil if the test fails. If "forTouch" is true, untouchable and invisible objects will cause the test to fail.

Parameters

localPoint: Point
forTouch: Boolean = false


initializeLMLNode ( id: String ): Void
Inherited from DisplayObject

Handle LML node initialization.

Parameters

id: String


invalidateBitmapCache (): Void
Inherited from DisplayObject

native

Update the cached texture before the next render. This function has no effect if cacheAsBitmap is turned off.



localToGlobal ( localPoint: Point ): Point
Inherited from DisplayObject

Transforms a point from the local coordinate system to global (stage) coordinates.

Parameters

localPoint: Point


pause (): Void

Pauses playback.



play (): Void

Starts playback. Beware that the clip has to be added to a juggler, too!



preinitializeLMLNode ( id: String ): Void
Inherited from DisplayObject

Pre-initialize the LML node.

Parameters

id: String


readjustSize (): Void
Inherited from Image

Readjusts the dimensions of the image according to its current texture. Call this method to synchronize image and texture size after assigning a texture with a different size.



removeEventListener ( type: String , listener: Function ): Void
Inherited from EventDispatcher

Removes an event listener from the object.

Parameters

type: String
listener: Function


removeEventListeners ( type: String = null ): Void
Inherited from EventDispatcher

Removes all event listeners with a certain type, or all of them if type is null. Be careful when removing all event listeners: you never know who else was listening.

Parameters

type: String = null


removeFrameAt ( frameID: Number ): Void

Removes the frame at a certain ID. The successors will move down.

Parameters

frameID: Number


removeFromParent ( dispose: Boolean = false ): Void
Inherited from DisplayObject

Removes the object from its parent, if it has one.

Parameters

dispose: Boolean = false


setFrameDuration ( frameID: Number , duration: Number ): Void

Sets the duration of a certain frame (in seconds).

Parameters

frameID: Number
duration: Number


setFrameSound ( frameID: Number , sound: String ): Void

Sets the sound of a certain frame. The sound will be played whenever the frame is displayed.

Parameters

frameID: Number
sound: String


setFrameTexture ( frameID: Number , texture: Texture ): Void

Sets the texture of a certain frame.

Parameters

frameID: Number
texture: Texture


setSize ( width: Number , height: Number ): Void
Inherited from Image

Manually set the size of the image to a specified width and height

Parameters

width: Number
height: Number


setTexCoords ( vertexID: Number , coords: Point ): Void
Inherited from Image

Sets the texture coordinates of a vertex. Coordinates are in the range [0, 1].

Parameters

vertexID: Number
coords: Point


setVertexAlpha ( vertexID: Number , alpha: Number ): Void
Inherited from Quad

Sets the alpha value of a vertex at a certain index.

Parameters

vertexID: Number
alpha: Number


setVertexColor ( vertexID: Number , color: Number ): Void
Inherited from Quad

Sets the color of a vertex at a certain index.

Parameters

vertexID: Number
color: Number


setVertexData ( pos: Vector.<Point> , uv: Vector.<Point> , color: Vector.<Number> , alpha: Vector.<Number> ): Void
Inherited from Quad

Fills in all of the vertex data for the quad with an arbitrary set of 4 position, UV, color (RGB), and alpha values. Make sure that data in the Vectors is ordered to correspond to the vertex index order of a Quad (see above).

Parameters

pos: Vector.<Point>
uv: Vector.<Point>
color: Vector.<Number>
alpha: Vector.<Number>


setVertexPosition ( vertexID: Number , posX: Number , posY: Number ): Void
Inherited from Quad

Sets the position of a vertex at a certain index.

Parameters

vertexID: Number
posX: Number
posY: Number


setVertexTexCoords ( vertexID: Number , u: Number , v: Number ): Void
Inherited from Quad

Sets the texture coordinates of a vertex at a certain index.

Parameters

vertexID: Number
u: Number
v: Number


stop (): Void

Stops playback, resetting "currentFrame" to zero.



toString (): String
Inherited from Object

native

Returns a String that describes the Object. This can be overriden to provide extra details when printing objects using trace().


Returns

String String that described the Object.

Protected functions

: