|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.flagstone.transform.action.NewFunction2
public final class NewFunction2
The NewFunction2 action is used to create a user-defined function with optimisations to improve performance.
NewFunction2 was added in Flash 7 to improve the performance of function calls by allowing pre-defined variables such as _root, _parent, _global, super, this and the arguments passed to the function to be pre-loaded to a set of up to 256 internal registers.
The optimisation attribute is a compound code, containing a number of flags that control which variables are pre-loaded:
| 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 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 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 list.
All the action objects added are owned by the function. They will be deleted when the function definition is deleted.
NewFunction| Nested Class Summary | |
|---|---|
static class |
NewFunction2.Builder
The Builder class is used to generate a new NewFunction2 object using a small set of convenience methods. |
static class |
NewFunction2.Optimization
The set of optimisations that can be used to speed up the execution of functions. |
| Constructor Summary | |
|---|---|
NewFunction2(NewFunction2.Builder builder)
Creates and initialises a NewFunction2 object using parameters defined in the Builder. |
|
NewFunction2(NewFunction2 object)
Creates and initialises a NewFunction2 action using the values copied from another NewFunction2 action. |
|
NewFunction2(String aString,
int count,
Set<NewFunction2.Optimization> opts,
Map<String,Integer> map,
List<Action> list)
Creates a NewFunction2 with the specified name, argument names and actions to be executed. |
|
NewFunction2(SWFDecoder coder,
Context context)
Creates and initialises a NewFunction2 definition using values encoded in the Flash binary format. |
|
| Method Summary | |
|---|---|
NewFunction2 |
copy()
Creates a complete copy of this object. |
void |
encode(SWFEncoder coder,
Context context)
Encode an object to the Flash binary format. |
List<Action> |
getActions()
Get the actions executed by the function. |
Map<String,Integer> |
getArguments()
Get the list of RegisterVariables that define the function arguments and whether they are assigned to internal registers or to local variables in memory. |
String |
getName()
Get the name of the function. |
Set<NewFunction2.Optimization> |
getOptimizations()
Get the list of Optimizations that will be used. |
int |
getRegisterCount()
Get the number of registers to allocate for function variables. |
int |
prepareToEncode(Context context)
Prepare an object for encoding, returning the expected size of an object when it is encoded. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public NewFunction2(NewFunction2.Builder builder)
builder - a Builder object containing the parameters to generate
the function definition.
public NewFunction2(SWFDecoder coder,
Context context)
throws IOException
coder - an SWFDecoder object that contains the encoded Flash data.context - a Context object used to manage the decoders for different
type of object and to pass information on how objects are
decoded.
IOException - if an error occurs while decoding the data.
public NewFunction2(String aString,
int count,
Set<NewFunction2.Optimization> opts,
Map<String,Integer> map,
List<Action> list)
aString - the name of the function. Can be an empty string if the
function is anonymous.count - the number of registers to allocate for variables.opts - the set of optimizations that will be applied to boost
function performance.map - the arguments and any register numbers they will be
assigned to (zero for no assignment).list - the list of actions that define the operation performed by
the function.public NewFunction2(NewFunction2 object)
object - a NewFunction2 action from which the values will be
copied. References to immutable objects will be shared.| Method Detail |
|---|
public String getName()
public int getRegisterCount()
public Set<NewFunction2.Optimization> getOptimizations()
public Map<String,Integer> getArguments()
public List<Action> getActions()
public NewFunction2 copy()
copy in interface Copyable<Action>public String toString()
toString in class Objectpublic int prepareToEncode(Context context)
prepareToEncode in interface SWFEncodeablecontext - an Context that allows information to be passed between
objects to control how they are initialised for encoding.
public void encode(SWFEncoder coder,
Context context)
throws IOException
encode in interface SWFEncodeablecoder - an SWFEncoder object.context - an Context that allows information to be passed between
objects to control how they are initialised for encoding.
IOException - if an error occurs while encoding the object.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||