|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.flagstone.transform.FSTransformObject
com.flagstone.transform.FSActionObject
com.flagstone.transform.FSNewFunction2
public class FSNewFunction2
The FSNewFunction2 action is used to create a user-defined function.
It was added in Flash 7 to improve the performance of function calls by allowing variables to be pre-loaded to a set of up to 256 internal registers and controlling the loading of pre-defined variables such as _root, _parent, _global, super, this and the arguments array containing the arguments passed to the function.
Attributes | |
---|---|
name | A string defining the name of the function. |
registerCount | The number of registers, up to 256, to allocate for storing variables. |
optimizations | A code consisting of a number of flags that control the execution environment for the function. |
arguments | An array of FSRegisterVariable objects containing the names of the arguments and whether they will be assigned to internal registers or defined in memory as local variables. The order of the FSRegisterVariable objects in the argument array indicate the order in which the values will be popped off the stack when the function is executed. The fist argument is popped from the stack first. |
actions | An array containing the actions that are executed. |
The optimisation attribute is a compound code, containing a number of flags that control how the environment of the function is initialised. Controlling the pre-defined variables that are created and pre-loading them into registers can significantly improve performance.
Environment | Description |
---|---|
CreateSuper | Create and initialise the super variable with the parent class of the function. |
CreateArguments | Create the arguments variable which contains the arguments passed to the function. |
CreateThis | Create the and initialise the this variable with the object. |
LoadThis | Pre-load the this variable into register number 1. |
LoadArguments | Pre-load the parent variable into register number 2. |
LoadSuper | Pre-load the super variable into register number 3. |
LoadRoot | Pre-load the _root variable into register number 4. |
LoadParent | Pre-load the _parent variable into register number 5. |
LoadGlobal | Pre-load the _global variable into register number 5. |
The register numbers that the predefined variables, this, parent, super, _root, _parent and _global are assigned to are fixed. When specifying which of the functions arguments are also assigned to registers it is important avoid these locations otherwise the variables will be overwritten.
User-defined functions are also used to create methods for user-defined objects. The name of the function is omitted and the function definition is assigned to a variable which allows it to be referenced at a alter time. See the example below.
The arguments supplied to the function can be referenced by the name supplied in the arguments array.
All the action objects added are owned by the function. They will be deleted when the function definition is deleted.
1. Define a function
Define a function that increments the value passed
to it:
// List the names of the arguments ArrayList arguments = new ArrayList(); arguments.add("value"); // Now define the actions performed by the function. Values passed to the function // can be referenced by the name defined in the array of arguments. ArrayList actions = new ArrayList(); actions.add(new FSPush("value")); actions.add(FSAction.GetVariable()); actions.add(new FSPush(1)); actions.add(FSAction.Add()); actions.add(FSAction.Return()); actions.add(new FSNewFunction2("increment", arguments, actions));
The function can then be referenced using it's name:
actions.add(new FSPush(1)); actions.add(new FSPush("increment")); actions.add(FSAction.ExecuteFunction());
2. Defining a method.
When creating a user-defined object the name of
the function can be omitted. Simply assign the function definition to a
variable:
actions.add(new FSPush(methodVariable)); FSVector<FSString> arguments; arguments.push_back("value"); ArrayList actions = new ArrayList(); actions.add(new FSPush("value")); actions.add(FSAction.GetVariable()); actions.add(new FSPush(1)); actions.add(FSAction.Add()); actions.add(FSAction.Return()); actions.add(new FSNewFunction2(arguments, actions)); actions.add(FSAction.SetVariable()));
The function can then be executed by pushing the arguments onto the stack then calling the function assigned to the variable:
// Push argument(s) onto stack actions.add(new FSPush(1)); // Get the variable that contains the function actions.add(new FSPush(methodVariable)); actions.add(FSAction.GetVariable()); // Execute the function actions.add(FSAction.ExecuteMethod());
3. Controlling the execution environment.
The code that defines the
optimizations that improve execution performance is created by bitwise-ORing
the individual flags together.
int optimizations = FSNewFunction2.CreateSuper | FSNewFunction2.PreloadSuper;
The FSNewFunction class represents the ActionDefineFunction2 action of the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 7.
Field Summary | |
---|---|
static int |
CreateArguments
Create and initialized the predefined variable, arguments. |
static int |
CreateSuper
Create and initialized the predefined variable, super. |
static int |
CreateThis
Create and initialized the predefined variable, this. |
static int |
LoadArguments
Load the predefine variable, arguments, into register 2. |
static int |
LoadGlobal
Load the predefine variable, _global, into register 6. |
static int |
LoadParent
Load the predefine variable, _parent, into register 5. |
static int |
LoadRoot
Load the predefine variable, _root, into register 4. |
static int |
LoadSuper
Load the predefine variable, super, into register 3. |
static int |
LoadThis
Load the predefine variable, this, into register 1. |
Fields inherited from class com.flagstone.transform.FSActionObject |
---|
Call, ExceptionHandler, GetUrl, GetUrl2, GotoFrame, GotoFrame2, GotoLabel, If, Jump, length, NewFunction, NewFunction2, Push, RegisterCopy, SetTarget, Table, type, WaitForFrame, WaitForFrame2, With |
Constructor Summary | |
---|---|
FSNewFunction2(java.util.ArrayList arguments,
java.util.ArrayList actions)
Constructs an anonymous FSNewFunction with the specified argument names and actions to be executed. |
|
FSNewFunction2(FSCoder coder)
Construct an FSNewFunction2 object, initialising it with values decoded from an encoded object. |
|
FSNewFunction2(FSNewFunction2 obj)
Constructs an FSNewFunction2 object by copying values from an existing object. |
|
FSNewFunction2(java.lang.String name,
java.util.ArrayList arguments,
java.util.ArrayList actions)
Constructs an FSNewFunction with the specified name, argument names and actions to be executed. |
Method Summary | |
---|---|
void |
add(FSActionObject anAction)
Adds the action object to the array of actions. |
void |
add(FSRegisterVariable anArgument)
Adds the name of an argument to the array of argument names. |
void |
appendDescription(java.lang.StringBuffer buffer,
int depth)
AppendDescription is used to present a string description of the object including all nested objects up to a specified depth. |
java.lang.Object |
clone()
Creates a deep copy of the entire object. |
void |
decode(FSCoder coder)
|
void |
encode(FSCoder coder)
|
boolean |
equals(java.lang.Object anObject)
Returns true if anObject is equal to this one. |
java.util.ArrayList |
getActions()
Gets the actions executed by the function. |
java.util.ArrayList |
getArguments()
Gets the array of FSRegisterVariables that define the function arguments and whether they are assigned to internal registers or to local variables in memory. |
java.lang.String |
getName()
Gets the name of the function. |
int |
getOptimizations()
Get the code containing the compound flags that control the execution environment of the function or method. |
int |
getRegisterCount()
Gets the number of registers to allocate for function variables. |
int |
length(FSCoder coder)
|
void |
setActions(java.util.ArrayList anArray)
Sets the actions. |
void |
setArguments(java.util.ArrayList anArray)
Sets the array of FSRegisterVariables that define the function arguments and whether they are assigned to internal registers or to local variables in memory. |
void |
setName(java.lang.String aString)
Sets the name of the function. |
void |
setOptimizations(int code)
Set the code containing the compound flags that control the execution environment of the function or method. |
void |
setRegisterCount(int count)
Sets the number of registers to allocate for function variables. |
Methods inherited from class com.flagstone.transform.FSActionObject |
---|
getType, length |
Methods inherited from class com.flagstone.transform.FSTransformObject |
---|
name, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int CreateSuper
public static final int CreateArguments
public static final int CreateThis
public static final int LoadThis
public static final int LoadArguments
public static final int LoadSuper
public static final int LoadRoot
public static final int LoadParent
public static final int LoadGlobal
Constructor Detail |
---|
public FSNewFunction2(FSCoder coder)
coder
- an FSCoder containing the binary data.public FSNewFunction2(java.lang.String name, java.util.ArrayList arguments, java.util.ArrayList actions)
name
- the name of the function.arguments
- an array of Strings listing the names of the arguments.actions
- the array of actions that define the operation performed by
the function.public FSNewFunction2(java.util.ArrayList arguments, java.util.ArrayList actions)
arguments
- an array of Strings listing the names of the arguments.actions
- the array of actions that define the operation performed by
the function.public FSNewFunction2(FSNewFunction2 obj)
obj
- an FSNewFunction2 object.Method Detail |
---|
public void add(FSRegisterVariable anArgument)
anArgument
- the name of an argument passed to the FSNewFunction object.public void add(FSActionObject anAction)
anAction
- an object belonging to a class derived from FSActionObject.public java.lang.String getName()
public void setName(java.lang.String aString)
aString
- the name of the function or null for a method.public int getRegisterCount()
public void setRegisterCount(int count)
count
- the number of registers to allocate.public int getOptimizations()
public void setOptimizations(int code)
code
- the compound code can be created by bitwise-ORing the
constants that identify the optimizations performed.public java.util.ArrayList getArguments()
public void setArguments(java.util.ArrayList anArray)
anArray
- an array of Strings listing the names of the arguments.public java.util.ArrayList getActions()
public void setActions(java.util.ArrayList anArray)
anArray
- the array of actions that define the operation performed by
the function.public java.lang.Object clone()
FSTransformObject
clone
in class FSTransformObject
public boolean equals(java.lang.Object anObject)
FSActionObject
equals
in class FSActionObject
public void appendDescription(java.lang.StringBuffer buffer, int depth)
FSTransformObject
appendDescription
in class FSTransformObject
buffer
- a StringBuffer to which the description of each object is
appended.depth
- the maximum level of nesting up to which objects will be
displayed.public int length(FSCoder coder)
length
in class FSActionObject
public void encode(FSCoder coder)
encode
in class FSActionObject
public void decode(FSCoder coder)
decode
in class FSActionObject
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |