|
|||||||||
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.FSNewFunction
public class FSNewFunction
The FSNewFunction action is used to create a user-defined function.
Attributes | |
---|---|
type | Identifies the data structure when it is encoded. The type attribute is read-only and may be used when iterating through an array of FSActionObjects to identify the object class without using run-time type checking. |
name | A string defining the name of the function. |
arguments | An array containing the names of the arguments. The order of the strings 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. |
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 FSNewFunction("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 FSNewFunction(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.ExecuteFunction());
The FSNewFunction class represents the ActionDefineFunction action of the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 5.
Field Summary |
---|
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 | |
---|---|
FSNewFunction(java.util.ArrayList argumentArray,
java.util.ArrayList actionArray)
Constructs an anonymous FSNewFunction with the specified argument names and actions to be executed. |
|
FSNewFunction(FSCoder coder)
Construct an FSNewFunction object, initialising it with values decoded from an encoded object. |
|
FSNewFunction(FSNewFunction obj)
Constructs an FSNewFunction object by copying values from an existing object. |
|
FSNewFunction(java.lang.String aString,
java.util.ArrayList argumentArray,
java.util.ArrayList actionArray)
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(java.lang.String 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. |
java.util.ArrayList |
getArguments()
Gets the names of the function arguments. |
java.lang.String |
getName()
Gets the name of the function. |
int |
length(FSCoder coder)
|
void |
setActions(java.util.ArrayList anArray)
Sets the actions. |
void |
setArguments(java.util.ArrayList anArray)
Sets the names of the function arguments. |
void |
setName(java.lang.String aString)
Sets the name of the function. |
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 |
Constructor Detail |
---|
public FSNewFunction(FSCoder coder)
coder
- an FSCoder containing the binary data.public FSNewFunction(java.lang.String aString, java.util.ArrayList argumentArray, java.util.ArrayList actionArray)
aString
- the name of the function.argumentArray
- an array of Strings listing the names of the arguments.actionArray
- the array of actions that define the operation performed by
the function.public FSNewFunction(java.util.ArrayList argumentArray, java.util.ArrayList actionArray)
argumentArray
- an array of Strings listing the names of the arguments.actionArray
- the array of actions that define the operation performed by
the function.public FSNewFunction(FSNewFunction obj)
obj
- an FSNewFunction object.Method Detail |
---|
public void add(java.lang.String 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 java.util.ArrayList getArguments()
public java.util.ArrayList getActions()
public void setName(java.lang.String aString)
aString
- the name of the function.public void setArguments(java.util.ArrayList anArray)
anArray
- an array of Strings listing the names of the arguments.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 |