libsswf: sswf::ActionFunction Class Reference

# sswf::ActionFunction Class Reference

The action to hold an ActionScript function. More...

`#include <libsswf.h>`

Inheritance diagram for sswf::ActionFunction:

List of all members.

## Public Types
enum | action_function_t { ACTION_FUNCTION_LOAD_THIS = 0x0001, ACTION_FUNCTION_SUPPRESS_THIS = 0x0002, ACTION_FUNCTION_LOAD_ARGUMENTS = 0x0004, ACTION_FUNCTION_SUPPRESS_ARGUMENTS = 0x0008, ACTION_FUNCTION_LOAD_SUPER = 0x0010, ACTION_FUNCTION_SUPPRESS_SUPER = 0x0020, ACTION_FUNCTION_LOAD_ROOT = 0x0040, ACTION_FUNCTION_LOAD_PARENT = 0x0080, ACTION_FUNCTION_LOAD_GLOBAL = 0x0100 }
| List the flags supported by the DeclareFunction2 tag. More...
enum | as_set_prop_flags_t { PROP_FLAG_IS_HIDDEN = 1, PROP_FLAG_CAN_DELETE = 2, PROP_FLAG_CAN_OVERWRITE = 4 }
| List of flags available to call the ASSetPropFlags() function. More...
## Public Member Functions
| ActionFunction (TagBase *tag, action_t action=ACTION_DECLARE_FUNCTION)
| Initializes ActionFunction objects.
void | AddAction (Action *action)
| Add an action in the function.
void | AddParameter (const char *name, int register_number=-1)
| Add a function parameter.
void | SetName (const char *name)
| Define the name of the function.
void | SetRegistersCount (unsigned int count)
| Set the maximum number of registers to use with this function.
virtual Vectors * | SubList (void)
| Get a pointer to the Vectors of sub-actions.
## Private Member Functions
virtual Action * | Duplicate (void) const
| Duplicate the function action.
virtual ErrorManager::error_code_t | ParseData (const Data &data)
| Parse the function definitions and then the nested actions.
virtual ErrorManager::error_code_t | SaveData (Data &data, Data &nested_data)
| Save the function header and nested data.
## Private Attributes
Vectors | f_actions
unsigned short | f_flags
char * | f_name
Vectors | f_parameters
unsigned int | f_registers_count
## Classes
struct | parameter_t
| Hold the parameters name and register number. More...

## Detailed Description

This class is used to create an ActionFunction, meaning a function to be called from within an ActionScript.

See also:
  SWF Alexis' Reference—Declare Function

  SWF Alexis' Reference—Declare Function (V7)

## Member Enumeration Documentation

enum sswf::ActionFunction::action_function_t

These flags can be used to very much optimize ActionScripts.

Each special variable and arguments to functions can be saved in registers for fast retrieval.

See also:
  SWF Alexis' Reference—Declare Function (V7)

Enumerator:

  ACTION_FUNCTION_LOAD_THIS | Make 'this' variable ready. The ACTION_FUNCTION_LOAD_THIS loads a register with the value of 'this'. The register depends on what is loaded before. See also: sswf::ActionFunction::ACTION_FUNCTION_SUPPRESS_THIS SWF Alexis' Reference—Declare Function (V7)
  ACTION_FUNCTION_SUPPRESS_THIS | Don't create the 'this' variable. The ACTION_FUNCTION_SUPPRESS_THIS can be used so 'this' variable is not even created. This can speed things up. See also: sswf::ActionFunction::ACTION_FUNCTION_LOAD_THIS SWF Alexis' Reference—Declare Function (V7)
  ACTION_FUNCTION_LOAD_ARGUMENTS | Load arguments in registers. The ACTION_FUNCTION_LOAD_ARGUMENTS loads a register with the value of each of the arguments specified when calling this function. The registers depend on what is loaded before. See also: sswf::ActionFunction::ACTION_FUNCTION_SUPPRESS_ARGUMENTS SWF Alexis' Reference—Declare Function (V7)
  ACTION_FUNCTION_SUPPRESS_ARGUMENTS | Ignore all arguments. The ACTION_FUNCTION_SUPPRESS_ARGUMENTS ensures that the ActionScript interpreter does not spend any time saving the arguments. This useful for virtual functions support. See also: sswf::ActionFunction::ACTION_FUNCTION_LOAD_ARGUMENTS SWF Alexis' Reference—Declare Function (V7)
  ACTION_FUNCTION_LOAD_SUPER | Make the 'super' variable ready. The ACTION_FUNCTION_LOAD_SUPER loads a register with the value of 'super'. The register depends on what is loaded before. See also: sswf::ActionFunction::ACTION_FUNCTION_SUPPRESS_SUPER SWF Alexis' Reference—Declare Function (V7)
  ACTION_FUNCTION_SUPPRESS_SUPER | Don't bother creating the 'super' variable. The ACTION_FUNCTION_SUPPRESS_SUPER asks the ActionScript interpreter to not bother creating the super variable. This can speed things up. See also: sswf::ActionFunction::ACTION_FUNCTION_LOAD_SUPER SWF Alexis' Reference—Declare Function (V7)
  ACTION_FUNCTION_LOAD_ROOT | Make the 'root' variable ready. The ACTION_FUNCTION_LOAD_ROOT loads a register with the value of 'root'. The register depends on what is loaded before. See also: sswf::ActionFunction::ACTION_FUNCTION_LOAD_THIS sswf::ActionFunction::ACTION_FUNCTION_LOAD_PARENT sswf::ActionFunction::ACTION_FUNCTION_LOAD_GLOBAL SWF Alexis' Reference—Declare Function (V7)
  ACTION_FUNCTION_LOAD_PARENT | Make the 'parent' variable ready. The ACTION_FUNCTION_LOAD_PARENT loads a register with the value of 'parent'. The register depends on what is loaded before. See also: sswf::ActionFunction::ACTION_FUNCTION_LOAD_THIS sswf::ActionFunction::ACTION_FUNCTION_LOAD_ROOT sswf::ActionFunction::ACTION_FUNCTION_LOAD_GLOBAL SWF Alexis' Reference—Declare Function (V7)
  ACTION_FUNCTION_LOAD_GLOBAL | Make the 'global' variable ready. The ACTION_FUNCTION_LOAD_THIS loads a register with the value of 'global'. The register depends on what is loaded before. See also: sswf::ActionFunction::ACTION_FUNCTION_SUPPRESS_THIS sswf::ActionFunction::ACTION_FUNCTION_LOAD_ROOT sswf::ActionFunction::ACTION_FUNCTION_LOAD_PARENT SWF Alexis' Reference—Declare Function (V7)

enum sswf::ActionFunction::as_set_prop_flags_t

This undocumented function is used to change the properties of an object variable member or function member. The properties are defined by three flags:

- Is hidden—whether the member can be seen by an enumeration action
- Can delete—whether the member can be removed
- Can overwrite—whether the member can be modified (this does not prevent the content of a variable member from being modified)

See also:
  sswf::ActionFunction::PROP_FLAG_IS_HIDDEN

  sswf::ActionFunction::PROP_FLAG_CAN_DELETE

  sswf::ActionFunction::PROP_FLAG_CAN_OVERWRITE

Enumerator:

  PROP_FLAG_IS_HIDDEN | Prevent the enumeration actions from showing this member. The PROP_FLAG_IS_HIDDEN flag, if set, prevents the enumeration functions from listing to corresponding member. See also: sswf::ActionFunction::PROP_FLAG_CAN_DELETE sswf::ActionFunction::PROP_FLAG_CAN_OVERWRITE
  PROP_FLAG_CAN_DELETE | Whether a member can be removed from an object. The PROP_FLAG_CAN_DELETE flag, if set, lets the user delete requests function. Once deleted, a member loses its property flag setup. If the member is re-created later, it may be required to set this flag again to delete it again. See also: sswf::ActionFunction::PROP_FLAG_IS_HIDDEN sswf::ActionFunction::PROP_FLAG_CAN_OVERWRITE
  PROP_FLAG_CAN_OVERWRITE | Whether a member can be overwritten in an object. The PROP_FLAG_CAN_OVERWRITE flag, if set, means that the corresponding member can be replaced (i.e. set with a different type, or in case of a function, by a different function.) This flag does not prevent a variable member from being modified. See also: sswf::ActionFunction::PROP_FLAG_IS_HIDDEN sswf::ActionFunction::PROP_FLAG_CAN_DELETE

## Constructor & Destructor Documentation

ActionFunction::ActionFunction | ( | TagBase * | tag,
|  | action_t | action = `ACTION_DECLARE_FUNCTION` |
| ) |  |  |

This function is used to initialize ActionFunction objects.

In debug mode it will test that the action is valid. It has to be set to either:

ACTION_DECLARE_FUNCTION or ACTION_DECLARE_FUNCTION2

The former can be used for movies version 5 or 6, the latter for movies version 7 or more.

Parameters:

  `[in]` | tag | The tag holding this action
  `[in]` | action | The type of function to create

References sswf::Action::ACTION_DECLARE_FUNCTION, sswf::Action::ACTION_DECLARE_FUNCTION2, sswf::assert(), f_flags, f_name, and f_registers_count.

Referenced by Duplicate().

## Member Function Documentation

void ActionFunction::AddAction | ( | Action * | action | ) |

Most functions include a set of actions to be executed when called. These actions are added using this functions. It is also possible to get a pointer to the sub-actions Vectors and directly add the actions in the Vectors object.

These actions are seen as the function block.

Parameters:

  `[in]` | action | The action to add to this function

See also:
  sswf::ActionFunction::SubList(void)

References f_actions, and sswf::Vectors::Set().

Referenced by Duplicate().

void ActionFunction::AddParameter | ( | const char * | name,
|  | int | register_number = `-1` |
| ) |  |  |

This function adds a parameter to the ActionFunction.

The name is mandatory for an ACTION_DECLARE_FUNCTION and optional for an ACTION_DECLARE_FUNCTION2. There are some special parameter names for an ACTION_DECLARE_FUNCTION2 to create or not system registers. The special names are as follow:

- this — put 'this' in a register
- /this — do not create 'this' even when available
- arguments — put 'arguments' in a register
- /arguments — do not create the 'arguments' array
- super — put 'super' in a register
- /super — do not create 'super'
- _root — put '_root' in a register
- /_root — cancel the action of '_root'
- _parent — put '_parent' in a register
- /_parent — cancel the action of '_parent'
- _global — put '_global' in a register
- /_global — cancel the action of '_global'

The register number is used only by an ACTION_DECLARE_FUNCTION2. By default the register number is set to -1 which means that no register is assigned to that parameter. You can use 0 to have the system automatically assign a register number to your parameter.

According to my testings, the register 255 cannot be used. So you are limited to a register number from 1 to 254. However, don't forget that system parameters must use the first few registers! If the register number you specify is larger than the one defined by the sswf::ActionFunction::SetRegistersCount(unsigned int count) then the count is increased as required.

Parameters:

  `[in]` | name | The name of the parameter
  `[in]` | register_number | The assigned register for that parameter

References sswf::Action::ACTION_DECLARE_FUNCTION2, ACTION_FUNCTION_LOAD_ARGUMENTS, ACTION_FUNCTION_LOAD_GLOBAL, ACTION_FUNCTION_LOAD_PARENT, ACTION_FUNCTION_LOAD_ROOT, ACTION_FUNCTION_LOAD_SUPER, ACTION_FUNCTION_LOAD_THIS, ACTION_FUNCTION_SUPPRESS_ARGUMENTS, ACTION_FUNCTION_SUPPRESS_SUPER, ACTION_FUNCTION_SUPPRESS_THIS, sswf::assert(), sswf::Action::f_action, f_flags, sswf::ActionFunction::parameter_t::f_name, f_parameters, sswf::ActionFunction::parameter_t::f_register_number, f_registers_count, sswf::MemoryManager::MemAttach(), sswf::Vectors::Set(), and sswf::MemoryManager::StrDup().

Referenced by Duplicate(), and ParseData().

Action * ActionFunction::Duplicate | ( | void |  | ) | const`[private, virtual]`

This function duplicates a function. This includes all the parameters and actions as well as the name and number of registers used in the list of parameters.

Returns:
  A pointer to a new ActionFunction object

Reimplemented from sswf::Action.

References ActionFunction(), AddAction(), AddParameter(), sswf::Vectors::Count(), sswf::Action::Duplicate(), sswf::Action::f_action, f_actions, f_flags, sswf::ActionFunction::parameter_t::f_name, f_name, f_parameters, sswf::ActionFunction::parameter_t::f_register_number, f_registers_count, sswf::Vectors::Get(), SetName(), SetRegistersCount(), and sswf::Action::Tag().

ErrorManager::error_code_t ActionFunction::ParseData | ( | const Data & | data | ) | `[private, virtual]`

This function parses the Function Action definitions (what registers are used) and then all the nested actions.

Parameters:

  `[in]` | data | The source Data buffer

Returns:
  An error code or ErrorManager::ERROR_CODE_NONE

Reimplemented from sswf::Action.

References sswf::Action::ACTION_DECLARE_FUNCTION2, AddParameter(), sswf::ErrorManager::ERROR_CODE_NONE, sswf::Action::f_action, f_actions, f_flags, f_name, f_registers_count, sswf::Data::GetByte(), sswf::Data::GetShort(), sswf::Data::GetString(), sswf::MemoryManager::MemClean(), sswf::Action::ParseList(), and sswf::Action::Tag().

ErrorManager::error_code_t ActionFunction::SaveData | ( | Data & | data,
|  | Data & | nested_data |
| ) |  |  | `[private, virtual]`

This function creates the function header which includes its name, all the parameters, whether to create or suppress system registers and the size of the function block.

Note that the function block cannot be larger than about 64Kb.

Parameters:

  `[in]` | data | The Data buffer where the function is saved
  `[in]` | nested_data | The Data buffer holding the function block

Returns:
  An error code or ErrorManager::ERROR_CODE_NONE

Reimplemented from sswf::Action.

References sswf::Action::ACTION_DECLARE_FUNCTION2, ACTION_FUNCTION_LOAD_GLOBAL, ACTION_FUNCTION_LOAD_PARENT, ACTION_FUNCTION_LOAD_ROOT, ACTION_FUNCTION_LOAD_SUPER, ACTION_FUNCTION_LOAD_THIS, sswf::Data::ByteSize(), sswf::Vectors::Count(), sswf::ErrorManager::ERROR_CODE_REGISTER_OVERFLOW, sswf::Action::f_action, f_flags, sswf::ActionFunction::parameter_t::f_name, f_name, f_parameters, sswf::ActionFunction::parameter_t::f_register_number, f_registers_count, sswf::Vectors::Get(), sswf::Action::GetMaxRegister(), sswf::ErrorManager::KeepFirst(), sswf::Action::OnError(), sswf::Data::PutByte(), sswf::Data::PutShort(), and sswf::Action::SaveString().

void ActionFunction::SetName | ( | const char * | name | ) |

This function saves the specified name as the name of the function.

This is the name you need to use to call the function later.

Note that an object function member has no name.

Parameters:

  `[in]` | name | The new function name

References f_name, sswf::MemoryManager::MemFree(), and sswf::MemoryManager::StrDup().

Referenced by Duplicate().

void ActionFunction::SetRegistersCount | ( | unsigned int | count | ) |

With an ACTION_DECLARE_FUNCTION2, you can use as many as 255 registers in your function, otherwise you are limited to 4 as before version 7. Also, before version 7, the parameters cannot automatically be assigned to registers and thus this function is not necessary.

Parameters:

  `[in]` | count | The number of registers you want to use

References f_registers_count.

Referenced by Duplicate().

Vectors * ActionFunction::SubList | ( | void |  | ) | `[virtual]`

This function can be used to retrieve a pointer to the sub-actions Vectors object. This can be used to add actions to the function in a way similar to the main block.

Returns:
  A pointer to a Vectors object expecting actions

Reimplemented from sswf::Action.

References f_actions.

## Member Data Documentation

Vectors sswf::ActionFunction::f_actions`[private]`

Referenced by AddAction(), Duplicate(), ParseData(), and SubList().

unsigned short sswf::ActionFunction::f_flags`[private]`

Referenced by ActionFunction(), AddParameter(), Duplicate(), ParseData(), and SaveData().

char* sswf::ActionFunction::f_name`[private]`

Referenced by ActionFunction(), Duplicate(), ParseData(), SaveData(), and SetName().

Vectors sswf::ActionFunction::f_parameters`[private]`

Referenced by AddParameter(), Duplicate(), and SaveData().

unsigned int sswf::ActionFunction::f_registers_count`[private]`

Referenced by ActionFunction(), AddParameter(), Duplicate(), ParseData(), SaveData(), and SetRegistersCount().

The documentation for this class was generated from the following files:

- libsswf.h
- libsswf_actions.c++