ActionScript® 3.0 Reference for the Adobe® Flash® Platform
Home  |  Show Packages and Classes List |  Packages  |  Classes  |  What's New  |  Index  |  Appendixes
fl.motion 

MotionBase  - AS3 Flash

Packagefl.motion
Classpublic class MotionBase
InheritanceMotionBase Inheritance Object
Subclasses Motion

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

The MotionBase class stores a keyframe animation sequence that can be applied to a visual object. The animation data includes position, scale, rotation, skew, color, filters, and easing. The MotionBase class has methods for retrieving data at specific keyframe points. To get interpolated values between keyframes, use the Motion class.

View the examples

Related API Elements



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  duration : int
Controls the Motion instance's length of time, measured in frames.
MotionBase
  is3D : Boolean
Specifies whether the motion contains 3D property changes.
MotionBase
  keyframes : Array
An array of keyframes that define the motion's behavior over time.
MotionBase
Public Methods
 MethodDefined By
  
MotionBase(xml:XML = null)
Constructor for MotionBase instances.
MotionBase
  
addFilterPropertyArray(index:int, name:String, values:Array, startFrame:int = -1, endFrame:int = -1):void
Modifies a filter property in all corresponding keyframes for a Motion object.
MotionBase
  
Adds a keyframe object to the Motion instance.
MotionBase
  
addPropertyArray(name:String, values:Array, startFrame:int = -1, endFrame:int = -1):void
Stores an array of values in corresponding keyframes for a declared property of the Motion class.
MotionBase
  
Retrieves an interpolated ColorTransform object at a specific time index in the Motion instance.
MotionBase
  
getCurrentKeyframe(index:int, tweenableName:String = ""):KeyframeBase
Retrieves the keyframe that is currently active at a specific frame in the Motion instance.
MotionBase
  
Retrieves an interpolated array of filters at a specific time index in the Motion instance.
MotionBase
  
Returns the Matrix object for the specified index position of the frame of animation.
MotionBase
  
Returns the Matrix3D object for the specified index position of the frame of animation.
MotionBase
  
getNextKeyframe(index:int, tweenableName:String = ""):KeyframeBase
Retrieves the next keyframe after a specific frame in the Motion instance.
MotionBase
  
getValue(index:Number, tweenableName:String):Number
Retrieves the value for an animation property at a point in time.
MotionBase
 Inherited
Indicates whether an object has a specified property defined.
Object
  
initFilters(filterClasses:Array, gradientSubarrayLengths:Array, startFrame:int = -1, endFrame:int = -1):void
Initializes the filters list for the target object and copies the list of filters to each Keyframe instance of the Motion object.
MotionBase
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
  
overrideTargetTransform(scale:Boolean = true, skew:Boolean = true, rotate:Boolean = true):void
MotionBase
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
  
setValue(index:int, tweenableName:String, value:Number):void
Sets the value of a specific tweenables property at a given time index in the Motion instance.
MotionBase
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
  
Rotates the target object when data for the motion is supplied by the addPropertyArray() method.
MotionBase
 Inherited
Returns the primitive value of the specified object.
Object
Property Detail

duration

property
duration:int

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Controls the Motion instance's length of time, measured in frames. The duration cannot be less than the time occupied by the Motion instance's keyframes.

The default value is 0.



Implementation
    public function get duration():int
    public function set duration(value:int):void

is3D

property 
is3D:Boolean

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 10, AIR 1.5, AIR 1.0

Specifies whether the motion contains 3D property changes. If true, the motion contains 3D property changes.

The default value is false.



Implementation
    public function get is3D():Boolean
    public function set is3D(value:Boolean):void

keyframes

property 
public var keyframes:Array

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

An array of keyframes that define the motion's behavior over time. This property is a sparse array, where a keyframe is placed at an index in the array that matches its own index. A motion object with keyframes at 0 and 5 has a keyframes array with a length of 6. Indices 0 and 5 in the array each contain a keyframe, and indices 1 through 4 have null values.

Constructor Detail

MotionBase

()Constructor
public function MotionBase(xml:XML = null)

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Constructor for MotionBase instances. By default, one initial keyframe is created automatically, with default transform properties.

Parameters
xml:XML (default = null) — Optional E4X XML object defining a Motion instance.
Method Detail

addFilterPropertyArray

()method
public function addFilterPropertyArray(index:int, name:String, values:Array, startFrame:int = -1, endFrame:int = -1):void

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Modifies a filter property in all corresponding keyframes for a Motion object. Call initFilters() before using this method. The order of the values in the array determines the assignment of each value to the filter property for all keyframes. For each non-null value in the specified values array, this method finds the keyframe corresponding to the value's index position in the array, and stores the property name/value pair for the filter in the keyframe.

Parameters

index:int — The zero-based index position in the array of filters.
 
name:String — The name of the filter property to store in each keyframe.
 
values:Array — The array of values for the property specified in the name parameter. Each non-null value is assigned to the filter in a keyframe that corresponds to the value's index in the array.
 
startFrame:int (default = -1)
 
endFrame:int (default = -1)

More examples

Related API Elements

addKeyframe

()method 
public function addKeyframe(newKeyframe:KeyframeBase):void

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Adds a keyframe object to the Motion instance.

Parameters

newKeyframe:KeyframeBase — A keyframe object with an index property already set.

Related API Elements

addPropertyArray

()method 
public function addPropertyArray(name:String, values:Array, startFrame:int = -1, endFrame:int = -1):void

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Stores an array of values in corresponding keyframes for a declared property of the Motion class. The order of the values in the array determines the assignment of each value to a keyframe. For each non-null value in the given values array, this method finds the keyframe corresponding to the value's index position in the array, or creates a new keyframe for that index position, and stores the property name/value pair in the keyframe.

Parameters

name:String — The name of the Motion class property to store in each keyframe.
 
values:Array — The array of values for the property specified in the name parameter. Each non-null value is assigned to a keyframe that corresponds to the value's order in the array.
 
startFrame:int (default = -1)
 
endFrame:int (default = -1)

More examples

Related API Elements

getColorTransform

()method 
public function getColorTransform(index:int):flash.geom:ColorTransform

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Retrieves an interpolated ColorTransform object at a specific time index in the Motion instance.

Parameters

index:int — The time index of a frame in the Motion instance, as an integer greater than or equal to zero.

Returns
flash.geom:ColorTransform — The interpolated ColorTransform object.

Related API Elements

getCurrentKeyframe

()method 
public function getCurrentKeyframe(index:int, tweenableName:String = ""):KeyframeBase

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Retrieves the keyframe that is currently active at a specific frame in the Motion instance. A frame that is not a keyframe derives its values from the keyframe that preceded it.

This method can also filter values by the name of a specific tweenables property. You can find the currently active keyframe for x, which may not be the same as the currently active keyframe in general.

Parameters

index:int — The index of a frame in the Motion instance, as an integer greater than or equal to zero.
 
tweenableName:String (default = "") — Optional name of a tweenable's property (like "x" or "rotation").

Returns
KeyframeBase — The closest matching keyframe at or before the supplied frame index.

Related API Elements

getFilters

()method 
public function getFilters(index:Number):Array

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Retrieves an interpolated array of filters at a specific time index in the Motion instance.

Parameters

index:Number — The time index of a frame in the Motion, as an integer greater than or equal to zero.

Returns
Array — The interpolated array of filters. If there are no applicable filters, returns an empty array.

Related API Elements

getMatrix

()method 
public function getMatrix(index:int):Matrix

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 10, AIR 1.5, AIR 1.0

Returns the Matrix object for the specified index position of the frame of animation.

Parameters

index:int — The zero-based index position of the frame of animation containing the matrix.

Returns
Matrix — The Matrix object, or null value. This method can return a null value even if MotionBase.is3D is false, because other motion tween property changes can be used without a Matrix object.

Related API Elements

getMatrix3D

()method 
public function getMatrix3D(index:int):Object

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 10, AIR 1.5, AIR 1.0

Returns the Matrix3D object for the specified index position of the frame of animation.

Parameters

index:int — The zero-based index position of the frame of animation containing the 3D matrix.

Returns
Object — The Matrix3D object, or null value. This method can return a null value even if MotionBase.is3D is true, because other 3D motion tween property changes can be used without a Matrix3D object.

Related API Elements

getNextKeyframe

()method 
public function getNextKeyframe(index:int, tweenableName:String = ""):KeyframeBase

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Retrieves the next keyframe after a specific frame in the Motion instance. If a frame is not a keyframe, and is in the middle of a tween, this method derives its values from both the preceding keyframe and the following keyframe.

This method also allows you to filter by the name of a specific tweenables property to find the next keyframe for a property, which might not be the same as the next keyframe in general.

Parameters

index:int — The index of a frame in the Motion instance, as an integer greater than or equal to zero.
 
tweenableName:String (default = "") — Optional name of a tweenable's property (like "x" or "rotation").

Returns
KeyframeBase — The closest matching keyframe after the supplied frame index.

Related API Elements

getValue

()method 
public function getValue(index:Number, tweenableName:String):Number

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Retrieves the value for an animation property at a point in time.

Parameters

index:Number — The time index of a frame in the Motion instance, as an integer greater than or equal to zero.
 
tweenableName:String — The name of a tweenable's property (like "x" or "rotation").

Returns
Number — The number value for the property specified in the tweenableName parameter.

Related API Elements

initFilters

()method 
public function initFilters(filterClasses:Array, gradientSubarrayLengths:Array, startFrame:int = -1, endFrame:int = -1):void

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Initializes the filters list for the target object and copies the list of filters to each Keyframe instance of the Motion object.

Parameters

filterClasses:Array — An array of filter classes. Each item in the array is the fully qualified class name (in String form) for the filter type occupying that index.
 
gradientSubarrayLengths:Array — An array of numbers containing a value for every filter that will be in the filters list for the motion (every class name in the filterClasses array). A value in the gradientSubarrayLengths array is only used if the filter class entry at the same index position in the filterClasses array is GradientGlowFilter or GradientBevelFilter. The corresponding value in the gradientSubarrayLengths array is a number that determines the length for the arrays that initialize the colors, alphas, and ratios parameters for the GradientGlowFilter and GradientBevelFilter constructor functions.
 
startFrame:int (default = -1)
 
endFrame:int (default = -1)

More examples

Related API Elements

overrideTargetTransform

()method 
public function overrideTargetTransform(scale:Boolean = true, skew:Boolean = true, rotate:Boolean = true):void

Parameters

scale:Boolean (default = true)
 
skew:Boolean (default = true)
 
rotate:Boolean (default = true)

setValue

()method 
public function setValue(index:int, tweenableName:String, value:Number):void

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Sets the value of a specific tweenables property at a given time index in the Motion instance. If a keyframe doesn't exist at the index, one is created automatically.

Parameters

index:int — The time index of a frame in the Motion instance, as an integer greater than zero. If the index is zero, no change is made. Transformation properties are relative to the starting transformation values of the target object, the values for the first frame (zero index value) are always default values and should not be changed.
 
tweenableName:String — The name of a tweenable's property as a string (like "x" or "rotation").
 
value:Number — The new value of the tweenable property.

Related API Elements

useRotationConcat

()method 
public function useRotationConcat(index:int):Boolean

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 10, AIR 1.5, AIR 1.0

Rotates the target object when data for the motion is supplied by the addPropertyArray() method.

Parameters

index:int — The index position of the frame of animation.

Returns
Boolean — Indicates whether the target object will rotate using the stored property from KeyframeBase.rotationConcat.

Related API Elements

MotionBaseExample.as

This example shows how to animate a sprite with the use of the MotionBase and AnimatorFactory classes. A MotionBase object is assigned arrays of x and y coordinates, and is then used to create an AnimatorFactory object. The AnimatorFactory is finally targeted to a sprite, in the form of a filled rectangle.
package 
{
     import flash.display.MovieClip;
     import flash.display.Sprite;
     import fl.motion.AnimatorFactory;
     import fl.motion.MotionBase;
     import flash.geom.Point;
    
     public class  MotionBaseExample extends MovieClip
     {
          private var motionBase:MotionBase;
          private var animFactory:AnimatorFactory;
          private var size:uint    = 100;
          private var bgColor:uint = 0xFFCC00;

          public function MotionBaseExample():void
          {
               var boxObj:sprite = new Sprite();
               boxObj.graphics.beginFill(bgColor);
               boxObj.graphics.drawRect(0, 0, size, size);
               boxObj.graphics.endFill();
               addChild(boxObj);

               motionBase = new MotionBase();
               motionBase.duration = 20;
               motionBase.addPropertyArray("x",[0,50,95,134,169,199,225,247,265,280]);
               motionBase.addPropertyArray("y",[0,1,0,4,12,21,32,44,52,38]);
               animFactory = new AnimatorFactory(motionBase);
               animFactory.transformationPoint = new Point(2, 2);
               animFactory.addTarget(boxObj, 0);
          }
     }    
}