Expansion Class Reference Manual


BACK TO README.htm

Here's a list of all the methods, properties and events contained in the Expansion class. The Expansion class controls several expanding parts of a character on the stage.


Index

Methods
Expansion Constructor
activate Start or stop the flow of time for the expandable parts.
getExpandableID Get the ID number of an expandable part.
insertExpandable Add an expandable part to the list.
removeExpandable Remove an expandable part from the list.
removeExpandableAt Remove an expandable part from the list.
getExpandable Get an expandable part from its ID number
getSize Get the size of an expandable part.
getMaxSize Get the maximum size of an expandable part.
getGrowth Get the growth rate of an expandable part.
setSize Set the size of an expandable part.
setMaxSize Set the maximum size of an expandable part.
setGrowth Set the growth rate of an expandable part.
setCheckPoint Create a checkpoint to watch for a certain size of an expandable part.
clearCheckPoint Remove a checkpoint.
getCheckPoint Get the name of the reaction the character has to the checkpoint.
Properties
numExpandables The number of expandable parts in the Expansion object.
size Set the size of all the expandable parts at once.
maxSize Set the maximum size of all the expandable parts at once.
growth Set the growth rate of all the expandable parts at once.
Events
"sizeChanged" Indicates that at least of the expandable parts has changed its size.
"checkpoint" Indicates that one of the expandable parts has reached the specific size that was being watched.

Methods


Expansion()

public function Expansion(stage:Stage)

Creates a new Expansion object. The expansion object controls the expansion of several parts of a character.

Parameters

stage:Stage A reference to the stage. Used for the enterFrame event handling.

activate()

public function activate(b:Boolean=true)

Starts the enterFrame handler if b is true, allowing time to flow for the expandable parts. Stops the enterFrame handler if b is false.

Parameters

b:Boolean A Boolean value indicating whether to activate or deactivate the expansion process.

getExpandableID()

public function getExpandableID(ex:MovieClip):int

Returns the ID number of the expandable part given in the parameter. Returns -1 if the part does not exist in the Expansion object.

Parameters

ex:MovieClip A reference to the MovieClip contained in the Expansion object.

Returns

The ID of the expandable part in the Expansion object.


insertExpandable()

public function insertExpandable(ex:MovieClip,maxSize:int=-1):int

Inserts the MovieClip into the Expansion object. Returns the ID number of the newly inserted MovieClip. If the MovieClip already exists, the maxSize parameter is updated for the expandable part.

Parameters

ex:MovieClip A reference to the MovieClip to be stored as an expandable part.
maxSize:int Indicates the frame of the MovieClip representing the end of the expansion. If this value is -1, the program will use the number of frames in the MovieClip as the maximum value. If the value is greater than the total number of frames, the program will reduce it to that number.

Returns

The ID of the expandable part in the Expansion object.


removeExpandable()

public function removeExpandable(ex:MovieClip)

Removes the MovieClip from the Expansion object. If the Expansion object does not contain the MovieClip, nothing will happen.

Parameters

ex:MovieClip A reference to the MovieClip to be removed from the expansion object.

removeExpandableAt()

public function removeExpandableAt(n:uint)

Given the ID in the first parameter, this function removes the expandable part from the Expansion object. If there is no expandable part associated with the ID number, nothing will happen

Parameters

n:uint The ID of the expandable part to be removed from the expansion object.

getExpandable()

public function getExpandable(n:uint):MovieClip

Given the ID in the first parameter, this function returns the associated expandable part from the Expansion object. If there is no expandable part associated with the ID number, it returns null.

Parameters

n:uint The ID of the expandable part to be returned.

Returns

The expandable part associated with the ID given in the parameter.


getSize()

public function getSize(n:uint):Number

Given the ID in the first parameter, this function returns the size of the associated expandable part from the Expansion object. If there is no expandable part associated with the ID number, it returns 0.

Parameters

n:uint The ID of the expandable part to get the size of.

Returns

The size of the expandable part associated with the ID given in the parameter.


getMaxSize()

public function getMaxSize(n:uint):uint

Given the ID in the first parameter, this function returns the maximum size of the associated expandable part from the Expansion object. If there is no expandable part associated with the ID number, it returns 0.

Parameters

n:uint The ID of the expandable part to get the maximum size of.

Returns

The maximum size of the expandable part associated with the ID given in the parameter.


getGrowth()

public function getGrowth(n:uint):Number

Given the ID in the first parameter, this function returns the growth rate of the associated expandable part from the Expansion object. If there is no expandable part associated with the ID number, it returns 0.

Parameters

n:uint The ID of the expandable part to get the growth rate of.

Returns

The growth rate of the expandable part associated with the ID given in the parameter.


setSize()

public function setSize(n:uint,s:Number)

Uses the second parameter to set the current size of the expandable part associated with the ID of the first parameter. The MovieClip's current frame is updated immediately.

Parameters

n:uint The ID of the expandable part to be modified.
s:Number The size to give to the expandable part.

setMaxSize()

public function setMaxSize(n:uint,s:uint)

Uses the second parameter to set the maximum size of the expandable part associated with the ID of the first parameter.

If the current size of the expandable part is greater than the new value of the maximum size, the expandable part's size will be set to the new maximum size and the MovieClip will be updated.

Parameters

n:uint The ID of the expandable part to be modified.
s:uint The maximum size to give to the expandable part.

setGrowth()

public function setGrowth(n:uint,s:Number)

Uses the second parameter to set the current size of the expandable part associated with the ID of the first parameter. The MovieClip's current frame is updated immediately.

Parameters

n:uint The ID of the expandable part to be modified.
s:uint The maximum size to give to the expandable part.

setCheckPoint()

public function setCheckPoint(expandable0:uint,size0:int,dir:int=1,reaction0:String="",timer0:int=30)

Creates a checkpoint for a specific size in a specific expandable part expanding in a specific direction.

The checkpoint watches the expansion of the expandable part given by "expandable0". When the size reaches "size0" and the growth rate has the same sign as the "dir", the Expansion object will fire the "checkpoint" event. You can capture this even using addEventListener().

See the checkpoint event for more information on the ExpansionEvent object.

Parameters

expandable0:uint The ID of the expandable part to watch.
size0:int The specific size to watch for. This value can only be an integer.
dir:int The direction of the expansion. This value must be either 1 or -.1. If it's 1, the checkpoint will only fire when the growth rate is positive. If it's -1, the checkpoint will only fire when the growth rate is negative.
reaction0:String The name of the reaction the character will have when this event fires. See Expression::react() for more information on reactions.
timer0:String The time the character will spend reacting after this event fires. See Expression::react() for more information on reactions.

Example

The following example watches for size 50 when expanding and size 1 when reverting:

var belly:MovieClip; //This Movieclip is already on the stage
var exp:Expansion = new Expansion(stage);
var bellyID:int = exp.insertExpandable(belly,50);
exp.setCheckPoint(bellyID,50,1);
exp.setCheckPoint(bellyID,1,-1);
exp.addEventListener("checkpoint",check);
exp.activate();
function check(E:ExpansionEvent){
   if(E.dir > 0){
      trace("Belly has expanded to its maximum size.");
   } else {
      trace("Belly has reverted to its minimum size.");
   }
}

clearCheckPoint()

public function clearCheckPoint(expandable0:uint,size0:int,dir:int=1)

Removes the checkpoint associated with the specific expandable object, target size and target direction. If there is no checkpoint for these values, nothing happens.

Parameters

expandable:uint The ID of the expandable part being watched.
size0:int The size being watched.
dir:int The direction being watched. This value should be 1 for positive growth or -1 for negative growth.

Example

The following example watches for size 50. When size 50 is locates, it reverts and clears the checkpoint:

var belly:MovieClip; //This Movieclip is already on the stage
var exp:Expansion = new Expansion(stage);
var bellyID:int = exp.insertExpandable(belly,50);
exp.setCheckPoint(bellyID,50,1);
exp.addEventListener("checkpoint",check);
exp.activate();
function check(E:ExpansionEvent){
   if(E.dir > 0){
      trace("Belly has expanded to its maximum size. Reverting.");
   }
   exp.clearCheckpoint(bellyID,50,1);
}

getCheckPoint()

public function getCheckPoint(expandable0:int,size0:int,dir:int=1):String

This function returns the name of the character's reaction to the checkpoint given by the first 3 parameters (See setCheckPoint() above for more details on these parameters).

If you gave a reaction name to each of your checkpoints, this function can be used to verify that the checkpoint actually exists. See Expression::react() for more information on reactions.

Parameters

expandable:uint The ID of the expandable part being watched.
size0:int The size being watched.
dir:int The direction being watched. This value should be 1 for positive growth or -1 for negative growth.

Returns

The expandable part associated with the ID given in the parameter.


Properties


numExpandables

public function get numExpandables():uint

A read-only variable that returns the number of expandable parts in the Expansion object.


size

public function set size(n:Number)

A write-only variable that lets you set the size of all the expandable parts at once. It follows the same rules as the setSize() function.


maxSize

public function set maxSize(n:uint)

A write-only variable that lets you set the maximum size of all the expandable parts at once. It follows the same rules as the setMaxSize() function.


growth

public function set growth(n:Number)

A write-only variable that lets you set the growth rate of all the expandable parts at once.


Events


"sizeChanged"

"sizeChanged"

This event fires if any of the expandable parts changes its size. You can use this to monitor the expansion of a character without creating a new "enterFrame" loop.

Example

This code traces the size of the "belly" each time it changes. Notice that the code will stop tracing values when the expansion reaches its limit.

var belly:MovieClip; //This MovieClip already exists on the stage
var exp:Expansion = new Expansion(stage);
var bellyID:int = exp.insertExpandable(belly);
exp.setGrowth(bellyID,1.0);
exp.addEventListener("sizeChanged",check);
exp.activate();
function check(E:Event){
   trace("Belly size:",exp.getSize(bellyID));
}

"checkpoint"

"checkpoint"

This event fires when a checkpoint has been reached in one of the expandable parts. To learn more about checkpoints and see an example of how they work, see the setCheckPoint() function above.

This event sends an ExpansionEvent object instead of a normal Event object. The ExpansionEvent object has these properties:

expandable:MovieClip The MovieClip object associated with the expandable part being watched.
size:int The size being watched.
direction:int The direction of the growth rate being watched. This value is either 1 or -1.
reaction:String The name of the reaction the character has when this checkpoint is reached.
timer:int The time the character will spend reacting after the event has fired.

The reaction and timer properties can be used as parameters in the Expression::react() function. Or, more conveniently, the Expression class can react automatically to the checkpoint by having it watch the Expansion object on its own, using the Expression::reactTo() function


BACK TO README.htm

© 2014 Doom the wolf. http://doom-the-wolf.deviantart.com