Class RMASNode
Encoding a tree of nodes to the binary Flash file format is performed in four stages:
1. First the nodes in the tree are re-ordered. This is used to move function definitions to the start of the block they are defined in - matching the behaviour performed by the Flash authoring application and making regression testing of the code generated against the code generated by Flash much easier.
2. then the node tree is searched for string literals, identifier and function names to construct a table of strings that is added to the start of the script, References to strings can then be made by specifying an index into the table rathe than pushing the string onto the Flash Player's stack - greatly reducing the size of the code.
3. The node tree is translated into an array of action objects. This intermediate step is required to calculate the relative branches and jumps performed when implementing if..else statements and construct such as for and while loops.
4. The array of actions generated by the translation step is then encoded to the binary data format support by Flash.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static HashMap
static HashMap
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorsConstructorDescriptionRMASNode
(int nodeType) Constructs an RMASNode with the specified type.RMASNode
(int nodeType, int value) Constructs an RMASNode with the specified type and integer value.Constructs an RMASNode with the specified type and adds the child node.Constructs an RMASNode with the specified type and adds the child nodes.Constructs an RMASNode with the specified type and string value. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a node to the array of children.int
count()
Return the number of child nodes contained by this node.void
displayTree
(String prefix) displayTree is used to display the structure of the node tree, with the root starting at the current node.byte[]
encode
(int version) The encode method 'compiles' the node and all child nodes into an array of action objects which represents the sequence of actions performed by the Flash Player.get
(int index) Returns the node at the specified index from the array of child nodes.int
Get the integer value assigned to a node.int
Get the number assigned to a node.Gets the parent node of this one.Get the string value assigned to a node.int
getType()
Gets the type of the node.int
Returns the index position of a node in the array of child nodes.void
Inserts a node at position i in the array of children.void
remove
(int index) Removes the node at position i in the array of children.void
Replaces the node at position i in the array of children.void
setIntValue
(int value) Set the integer value assigned to a node.void
setNumber
(int value) Set the number assigned to a node.void
setStringValue
(String value) Set the string value assigned to a node.void
setType
(int type) Sets the type of the node.toString()
Returns a string containing the type of node, any associated value and the number of children.void
validate()
validate is used to provide additional error checking not covered in the parser grammar.
-
Field Details
-
Frame
public static final int Frame- See Also:
-
Button
public static final int Button- See Also:
-
MovieClip
public static final int MovieClip- See Also:
-
List
public static final int List- See Also:
-
NoOp
public static final int NoOp- See Also:
-
If
public static final int If- See Also:
-
For
public static final int For- See Also:
-
ForIn
public static final int ForIn- See Also:
-
While
public static final int While- See Also:
-
Do
public static final int Do- See Also:
-
With
public static final int With- See Also:
-
OnClipEvent
public static final int OnClipEvent- See Also:
-
On
public static final int On- See Also:
-
Break
public static final int Break- See Also:
-
Return
public static final int Return- See Also:
-
Continue
public static final int Continue- See Also:
-
Value
public static final int Value- See Also:
-
Literal
public static final int Literal- See Also:
-
Identifier
public static final int Identifier- See Also:
-
Attribute
public static final int Attribute- See Also:
-
Method
public static final int Method- See Also:
-
Function
public static final int Function- See Also:
-
NewObject
public static final int NewObject- See Also:
-
Subscript
public static final int Subscript- See Also:
-
DefineFunction
public static final int DefineFunction- See Also:
-
DefineArray
public static final int DefineArray- See Also:
-
DefineObject
public static final int DefineObject- See Also:
-
DefineMethod
public static final int DefineMethod- See Also:
-
DefineAttribute
public static final int DefineAttribute- See Also:
-
DefineVariable
public static final int DefineVariable- See Also:
-
Add
public static final int Add- See Also:
-
Sub
public static final int Sub- See Also:
-
Mul
public static final int Mul- See Also:
-
Div
public static final int Div- See Also:
-
Mod
public static final int Mod- See Also:
-
LSL
public static final int LSL- See Also:
-
ASR
public static final int ASR- See Also:
-
LSR
public static final int LSR- See Also:
-
BitAnd
public static final int BitAnd- See Also:
-
BitOr
public static final int BitOr- See Also:
-
BitXOr
public static final int BitXOr- See Also:
-
And
public static final int And- See Also:
-
Or
public static final int Or- See Also:
-
Equal
public static final int Equal- See Also:
-
NotEqual
public static final int NotEqual- See Also:
-
GreaterThan
public static final int GreaterThan- See Also:
-
LessThan
public static final int LessThan- See Also:
-
GreaterThanEqual
public static final int GreaterThanEqual- See Also:
-
LessThanEqual
public static final int LessThanEqual- See Also:
-
Select
public static final int Select- See Also:
-
Not
public static final int Not- See Also:
-
BitNot
public static final int BitNot- See Also:
-
Plus
public static final int Plus- See Also:
-
Minus
public static final int Minus- See Also:
-
PreInc
public static final int PreInc- See Also:
-
PreDec
public static final int PreDec- See Also:
-
PostInc
public static final int PostInc- See Also:
-
PostDec
public static final int PostDec- See Also:
-
Assign
public static final int Assign- See Also:
-
AssignAdd
public static final int AssignAdd- See Also:
-
AssignSub
public static final int AssignSub- See Also:
-
AssignMul
public static final int AssignMul- See Also:
-
AssignDiv
public static final int AssignDiv- See Also:
-
AssignMod
public static final int AssignMod- See Also:
-
AssignLSL
public static final int AssignLSL- See Also:
-
AssignASR
public static final int AssignASR- See Also:
-
AssignLSR
public static final int AssignLSR- See Also:
-
AssignBitAnd
public static final int AssignBitAnd- See Also:
-
AssignBitOr
public static final int AssignBitOr- See Also:
-
AssignBitXOr
public static final int AssignBitXOr- See Also:
-
buttonEvents
-
clipEvents
-
-
Constructor Details
-
RMASNode
public RMASNode(int nodeType) Constructs an RMASNode with the specified type.- Parameters:
nodeType
- the type of node being constructed.
-
RMASNode
public RMASNode(int nodeType, int value) Constructs an RMASNode with the specified type and integer value. This constructor is primarily used to create nodes representing integer literals.- Parameters:
nodeType
- the type of node being constructed.value
- the integer value assigned to the node.
-
RMASNode
Constructs an RMASNode with the specified type and string value. This constructor is primarily used to create string literals and identifiers.- Parameters:
nodeType
- the type of node being constructed.value
- the string assigned to the node.
-
RMASNode
Constructs an RMASNode with the specified type and adds the child node.- Parameters:
nodeType
- the type of node being constructed.node
- a child node which will be added to the new node.
-
RMASNode
Constructs an RMASNode with the specified type and adds the child nodes.- Parameters:
nodeType
- the type of node being constructed.node1
- a child node which will be added to the new node.node2
- a child node which will be added to the new node.
-
-
Method Details
-
getType
public int getType()Gets the type of the node.- Returns:
- the type assigned to the node.
-
setType
public void setType(int type) Sets the type of the node.- Parameters:
type
- the type assigned to the node.
-
getIntValue
public int getIntValue()Get the integer value assigned to a node.- Returns:
- the integer value assigned to a node.
-
setIntValue
public void setIntValue(int value) Set the integer value assigned to a node.- Parameters:
value
- a value that will be assigned to the node.
-
getStringValue
Get the string value assigned to a node.- Returns:
- the string value assigned to a node.
-
setNumber
public void setNumber(int value) Set the number assigned to a node.- Parameters:
value
- a unique number that will be assigned to the node.
-
getNumber
public int getNumber()Get the number assigned to a node.- Returns:
- the number assigned to a node.
-
setStringValue
Set the string value assigned to a node.- Parameters:
value
- a string that will be assigned to the node.
-
get
Returns the node at the specified index from the array of child nodes. If the index is outside the range of the array then an ArrayIndexOutOfBounds exception is thrown.- Parameters:
index
- the index of the child node to return.- Returns:
- the ith node in the array of children.
- Throws:
ArrayIndexOutOfBoundsException
- if (index < 0 || index >= length).
-
set
Replaces the node at position i in the array of children. If the position is outside the range of the array (i< 0 || i >= length) then an ArrayIndexOutOfBoundsException is thrown.- Parameters:
i
- the index of the child node to replace.aNode
- the node to replace the ith node.- Throws:
ArrayIndexOutOfBoundsException
- if (index < 0 || index >= length).
-
add
Adds a node to the array of children. If the node is null then it is ignored.- Parameters:
aNode
- the node to be added.
-
insert
Inserts a node at position i in the array of children. The size of the array is increased by one and the nodes from the insertion point onwards are moved to the right.If the position is outside the range of the array (i< 0 || i >= length) then an ArrayIndexOutOfBoundsException is thrown.
- Parameters:
index
- the index of the child node to replace.aNode
- the node to replace the ith node.- Throws:
ArrayIndexOutOfBoundsException
- if (index < 0 || index >= length).
-
remove
public void remove(int index) Removes the node at position i in the array of children. The size of the array is decreased by one and the nodes from the insertion point onwards are moved to the left.If the position is outside the range of the array (i< 0 || i >= length) then an ArrayIndexOutOfBoundsException is thrown.
- Parameters:
index
- the index of the child node to remove.- Throws:
ArrayIndexOutOfBoundsException
- if (index < 0 || index >= length).
-
indexOf
Returns the index position of a node in the array of child nodes. If the node is not one of the current nodes children then -1 is returned.- Parameters:
aNode
- the node to search the array of children for.- Returns:
- the index of the node in the array of children, -1 if the node is not a child of this node.
-
getParent
Gets the parent node of this one. If no parent is define then null is returned.- Returns:
- the parent node of this one.
-
count
public int count()Return the number of child nodes contained by this node.- Returns:
- the number of child nodes.
-
toString
Returns a string containing the type of node, any associated value and the number of children. -
displayTree
displayTree is used to display the structure of the node tree, with the root starting at the current node. The prefix argument is used to ident the text displayed. The level of indent is increased by appending the string " " before calling the displayTree method on each child node. This illustrates the tree structure with nodes at the same level in the tree displayed with the same level of indent.- Parameters:
prefix
- the string prepended to the text representation for this node.
-
encode
public byte[] encode(int version) The encode method 'compiles' the node and all child nodes into an array of action objects which represents the sequence of actions performed by the Flash Player. The actions are then encoded to generate the binary data that can be added to an encoded Flash file.The version of Flash for which the actions are generated is specified to ensure compatibility with future release of Flash.
IMPORTANT: The programming model changed with Flash version 5 to support stack-based actions. Earlier versions of Flash are not support. An IllegalArgumentexception will be thrown if the version is earlier than 5.
- Parameters:
version
- the version of Flash that control the actions that are generated.version
- the version of Flash that the script should be encoded for.- Returns:
- an array of bytes containing encoded action objects.
- Throws:
IllegalArgumentexception
- is the version is less than 5.
-
validate
validate is used to provide additional error checking not covered in the parser grammar.- Throws:
ParseException
-