StatedMovieClip
Kind of class: | class |
---|---|
Inherits from: | CoreMovieClip < MovieClip |
Known subclasses: | |
Version: | 05/13/07 |
Author: | Toby Boudreaux, David Nelson, Aaron Clinger |
Classpath: | org.casalib.movieclip.StatedMovieClip |
File last modified: | Monday, 01 December 2008, 13:34:40 |
Provides state-switching mechanism for MovieClip event handlers and properties.
Example:
-
import org.casalib.util.MovieClipUtil; MovieClipUtil.attachMovieRegisterClass(org.casalib.movieclip.StatedMovieClip, this, "linkageMovieClip", "stated_mc"); this.stated_mc.onRelease = function():Void { trace("onRelease on " + this._name + " was called. Example one."); } this.stated_mc.createState("exampleButtonOne"); this.stated_mc.onRelease = function():Void { trace("onRelease on " + this._name + " was called. Example two."); } this.stated_mc.createState("exampleButtonTwo");
Now you can switch between the states, example:
this.stated_mc.switchState("exampleButtonOne");
orthis.stated_mc.switchState("exampleButtonTwo");
To return to the default creation state call:
this.stated_mc.switchState("default");
To remove all event handlers call:
this.stated_mc.switchState("blank");
Usage note:
- Class creates
"default"
and"blank"
states during MovieClip instance creation.
Summary
Class methods
- create (target:MovieClip, instanceName:String, depth:Number, initObject:Object) : StatedMovieClip
- Creates an empty instance of the StatedMovieClip class.
Class methods inherited from CoreMovieClip
Instance methods
- getState : String
- Returns the current state of MovieClip.
- switchState (stateName:String, inclusionList:Array) : Boolean
- Switches MovieClip's current state to a precreated state.
- createState (stateName:String, inclusionList:Array) : Void
- Creates a new state and records event handlers.
- setKeyValueForState (stateName:String, keyName:String, value:Object) : Void
- Registers single value to a MovieClip property for a given state.
- removeKeyValueForState (stateName:String, keyName:String) : Boolean
- Removes/unregisters value from MovieClip property for a given state.
- removeState (stateName:String) : Boolean
- Deletes precreated MovieClip state.
- destroy : Void
Instance methods inherited from CoreMovieClip
Class methods
create
static function create (
target:MovieClip,
instanceName:String,
depth:Number,
initObject:Object) : StatedMovieClip
Creates an empty instance of the StatedMovieClip class. Use this instead of a traditional
new
constructor statement due to limitations of ActionScript 2.0. Parameters:
target :
Location where the MovieClip should be attached.
instanceName:
A unique instance name for the MovieClip.
depth :
[optional] The depth level where the MovieClip is placed; defaults to next highest open depth.
initObject :
[optional] An object that contains properties with which to populate the newly attached MovieClip.
Returns:
- Returns a reference to the created instance.
Example:
-
var myStated_mc:StatedMovieClip = StatedMovieClip.create(this, "example_mc");
Usage note:
- If you want to extend a non empty MovieClip you can either define the ActionScript 2.0 class in the Flash IDE library or use org.casalib.util.MovieClipUtil.attachMovieRegisterClass.
Since:
- Flash Player 7
Instance methods
createState
function createState (
stateName:String,
inclusionList:Array) : Void
Creates a new state and records event handlers.
Parameters:
stateName :
Unique name for MovieClip state.
inclusionList:
[optional] List of event handlers and properties to include. Defaults to all MovieClip event handlers.
Usage note:
- If parameter
stateName
is identical to previously created state, createState will overwrite it.
Example:
-
this.stated_mc.createState("uniqueStateName", new Array("onRollOver", "onRollOut", "onRelease"));
getState
function getState (
) : String
Returns the current state of MovieClip. If no state has been created getState will return
"default"
. Returns:
- The name of current MovieClip state.
Usage note:
- getState will always return last created or switched to state.
removeKeyValueForState
function removeKeyValueForState (
stateName:String,
keyName:String) : Boolean
Removes/unregisters value from MovieClip property for a given state.
Parameters:
stateName:
Name of precreated MovieClip state.
keyName :
Name of any MovieClip property or event handler.
Returns:
- Returns
true
if the key was successfully found and removed from event handler state; otherwisefalse
.
removeState
function removeState (
stateName:String) : Boolean
Deletes precreated MovieClip state.
Parameters:
stateName:
Name of precreated MovieClip state.
Returns:
- Returns
true
if the state was successfully found and removed; otherwisefalse
.
setKeyValueForState
function setKeyValueForState (
stateName:String,
keyName:String,
value:Object) : Void
Registers single value to a MovieClip property for a given state.
Parameters:
stateName:
Name of precreated MovieClip state, or new state.
keyName :
Name of any MovieClip property or event handler.
value :
Value of MovieClip property or event handler specified by parameter
keyName
.Example:
-
var anonymousFunction:Function = function():Void { trace("onRollOver"); } this.stated_mc.setKeyValueForState("stateName", "onRollOver", anonymousFunction);
You can define any MovieClip properties, not just event handlers. Such as_alpha
,_x
,_yscale
etc...:
this.stated_mc.setKeyValueForState("stateName", "_alpha", 25);
switchState
function switchState (
stateName:String,
inclusionList:Array) : Boolean
Switches MovieClip's current state to a precreated state.
Parameters:
stateName :
Name of precreated MovieClip state.
inclusionList:
[optional] List of event handlers and properties to include/switch state of. Defaults to all MovieClip event handlers.
Returns:
- Returns
true
if the precreated state was found and the MovieClip's state was successfully changed; otherwisefalse
.
Example:
-
this.stated_mc.switchState("uniqueStateName", new Array("onEnterFrame", "onRelease"));
See also: