com.flagstone.transform
Class FSTableIndex

java.lang.Object
  extended by com.flagstone.transform.FSTransformObject
      extended by com.flagstone.transform.FSTableIndex
All Implemented Interfaces:
java.lang.Cloneable

public class FSTableIndex
extends FSTransformObject

FSTableIndex is used with an FSPush action to push a reference to an entry in a table of literals onto the stack.

The value is can then be retrieved from the table and used in a subsequent calculation. The data type was extended in Flash 6 to support tables of up to 65535 strings.

In the Macromedia Flash (SWF) File Format Specification all literals used in calculations are stored as strings. When performing a series of actions each time a literal value is used in a calculation it must be pushed onto the stack. Rather than repeatedly pushing the value explicitly using an FSPush action, all the literals are added to a table in the Flash Player's memory using the FSTable action. To retrieve a literal from the table a reference to an entry in the table is pushed onto the stack using an FSTableIndex. The reduces the number of bytes required to perform a given calculation when the values are used repeatedly.

As an example consider the code required to concatenate two strings:

  ArrayList actions = new ArrayList();
  ...
  // Create the table of literals
  FSTable literals = new FSTable();
  literals.add("abc");
  literals.add("def");
  actions.add(literals);
  ...
  // Create references to the string literals
  FSPush push = new FSPush();
  push.add(new FSTableIndex(0));
  push.add(new FSTableIndex(1));
  actions.add(push);
  ...
  // concatenate the strings
  actions.add(new FSAction(FSAction.Add));
 

An FSTable can store up to 65536 string literals. Using a table index rather than specifying the string literal explicitly reduces considerably the number of bytes required to represent a sequence of actions.

History

The string literal table was introduced in Flash 5. It was extended in Flash 6 to support tables of up to 65536 strings.


Constructor Summary
FSTableIndex(FSCoder coder)
          Construct an FSTableIndex object, initalizing it with values decoded from an encoded object.
FSTableIndex(FSTableIndex obj)
          Constructs an FSTableIndex object by copying values from an existing object.
FSTableIndex(int anIndex)
          Constructs an FSTableIndex object referencing the value stored in the literal table.
 
Method Summary
 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.
 void decode(FSCoder coder)
           
 void encode(FSCoder coder)
           
 boolean equals(java.lang.Object anObject)
          Returns true if anObject is equal to this one.
 int getIndex()
          Gets the index in the table of string literals.
 int length(FSCoder coder)
           
 void setIndex(int anIndex)
          Sets the index in the table of string literals.
 
Methods inherited from class com.flagstone.transform.FSTransformObject
clone, name, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FSTableIndex

public FSTableIndex(FSCoder coder)
Construct an FSTableIndex object, initalizing it with values decoded from an encoded object.

Parameters:
coder - an FSCoder containing the binary data.

FSTableIndex

public FSTableIndex(int anIndex)
Constructs an FSTableIndex object referencing the value stored in the literal table.

Parameters:
anIndex - the index into the literal table.

FSTableIndex

public FSTableIndex(FSTableIndex obj)
Constructs an FSTableIndex object by copying values from an existing object.

Parameters:
obj - an FSTableIndex object.
Method Detail

getIndex

public int getIndex()
Gets the index in the table of string literals.

Returns:
the index into the literal table.

setIndex

public void setIndex(int anIndex)
Sets the index in the table of string literals.

Parameters:
anIndex - the index into the literal table.

equals

public boolean equals(java.lang.Object anObject)
Returns true if anObject is equal to this one. Objects are considered equal if they would generate identical binary data when they are encoded to a Flash file.

Overrides:
equals in class FSTransformObject
Returns:
true if this object would be identical to anObject when encoded.

appendDescription

public void appendDescription(java.lang.StringBuffer buffer,
                              int depth)
Description copied from class: FSTransformObject
AppendDescription is used to present a string description of the object including all nested objects up to a specified depth. This method provide a more controlled way of creating a string representation of an object since large objects such as font or shape definitions can contain dozens of nested objects. The representation of the object is appended to the StringBuffer, showing the name of the class and values of the attributes it contains. If the object contains any attributes that are objects then the object graph will be traversed up to the specified depth. If objects are nested at a level less than specified depth then the full string representation of the object is displayed. For objects at the specified depth only the name of the class is displayed. Any objects below this depth are not displayed.

Specified by:
appendDescription in class FSTransformObject
Parameters:
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.

length

public int length(FSCoder coder)
Specified by:
length in class FSTransformObject

encode

public void encode(FSCoder coder)
Specified by:
encode in class FSTransformObject

decode

public void decode(FSCoder coder)
Specified by:
decode in class FSTransformObject