[] → [function]
0x8e
0 → 1
7
(6.65
)The length in the action header ignores the function body.
ActionDefineFunction2 is similar to ActionDefineFunction, with additional features that can help speed up the execution of function calls by preventing the creation of unused variables in the function’s activation object and by enabling the replacement of local variables with a variable number of registers. With ActionDefineFunction2, a function can allocate its own private set of up to 256 registers. Parameters or local variables can be replaced with a register, which is loaded with the value instead of the value being stored in the function’s activation object. (The activation object is an implicit local scope that contains named arguments and local variables. For further description of the activation object, see the ECMA-262 standard.)
ActionDefineFunction2 also includes six flags to instruct Flash Player to preload variables, and three flags to suppress variables. By setting PreloadParentFlag, PreloadRootFlag, PreloadSuperFlag, PreloadArgumentsFlag, PreloadThisFlag, or PreloadGlobalFlag, common variables can be preloaded into registers before the function executes (_parent, _root, super, arguments, this, or _global, respectively). With flags SuppressSuper, SuppressArguments, and SuppressThis, common variables super, arguments, and this are not created. By using suppress flags, Flash Player avoids pre- evaluating variables, thus saving time and improving performance.
No suppress flags are provided for _parent, _root, or _global because Flash Player always evaluates these variables as needed; no time is ever wasted on pre-evaluating these variables.
Specifying both the preload flag and the suppress flag for any variable is not allowed.
The body of the function that ActionDefineFunction2 specifies should use ActionPush and ActionStoreRegister for local variables that are assigned to registers. ActionGetVariable and ActionSetVariable cannot be used for variables assigned to registers.
Flash Player 6 release 65 and later supports ActionDefineFunction2.
Field | Type | Comment |
---|---|---|
ActionDefineFunction2 | ACTIONRECORDHEADER | ActionCode = 0x8E |
FunctionName | STRING | Name of function, empty if anonymous |
NumParams | UI16 | # of parameters |
RegisterCount | UI8 | Number of registers to allocate, (from 0 to 254) up to 255 registers |
PreloadParentFlag | UB[1] |
0 = Don’t preload _parent into register 1 = Preload _parent into register |
PreloadRootFlag | UB[1] |
0 = Don’t preload _root into register 1 = Preload _root into register |
SuppressSuperFlag | UB[1] |
0 = Create super variable 1 = Don't create super variable |
PreloadSuperFlag | UB[1] |
0 = Don’t preload super into register 1 = Preload super into register |
SuppressArgumentsFlag | UB[1] |
0 = Create arguments variable 1 = Don't create arguments variable |
PreloadArgumentsFlag | UB[1] |
0 = Don’t preload arguments into register 1 = Preload arguments into register |
SuppressThisFlag | UB[1] |
0 = Create this variable 1 = Don't create this variable |
PreloadThisFlag | UB[1] |
0 = Don’t preload this into register 1 = Preload this into register |
Reserved | UB[7] | Always 0 |
PreloadGlobalFlag | UB[1] |
0 = Don’t preload _global into register 1 = Preload _global into register |
Parameters | REGISTERPARAM[NumParams] | See REGISTERPARAM, following |
codeSize | UI16 | # of bytes of code that follow |
Field | Type | Comment |
---|---|---|
Register | UI8 | For each parameter to the function, a register can be specified. If the register specified is zero, the parameter is created as a variable named ParamName in the activation object, which can be referenced with ActionGetVariable and ActionSetVariable. If the register specified is nonzero, the parameter is copied into the register, and it can be referenced with ActionPush and ActionStoreRegister, and no variable is created in the activation object. |
ParamName | STRING | Parameter name |