com.flagstone.transform.action
Class RegisterCopy

java.lang.Object
  extended by com.flagstone.transform.action.RegisterCopy
All Implemented Interfaces:
Action, Copyable<Action>, SWFEncodeable

public final class RegisterCopy
extends Object
implements Action

RegisterCopy is used to copy the item at the top of the stack to one of the Flash Player's internal registers.

The Flash Player uses a stack to store values when executing the actions associated with a button being pushed, frame being played, etc. If a value is used repeatedly in a calculation, it must be pushed onto the stack each time using an Push action. To speed up the execution of the calculation and reduce the amount of code required the value can be saved to one of the internal registers of the Flash Player using the RegisterCopy action. This copies the value currently at the top of the stack into the specified register. Pushing an RegisterIndex object onto the stack creates a reference to the register so the Flash Player uses the value directly rather than pushing the value onto the stack then immediately popping to use the value in a calculation.

The value is not removed from the stack. The number of registers supported was expanded in Flash 7 from 4 to 256.

See Also:
RegisterIndex, Push

Constructor Summary
RegisterCopy(int register)
          Creates a RegisterCopy object with the register number.
RegisterCopy(RegisterCopy object)
          Creates and initialises a RegisterCopy action using the values copied from another RegisterCopy action.
RegisterCopy(SWFDecoder coder)
          Creates and initialises a RegisterCopy action using values encoded in the Flash binary format.
 
Method Summary
 RegisterCopy copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 int getNumber()
          Returns the number of the Player register that the value on the stack will be copied to.
 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

RegisterCopy

public RegisterCopy(SWFDecoder coder)
             throws IOException
Creates and initialises a RegisterCopy action using values encoded in the Flash binary format.

Parameters:
coder - an SWFDecoder object that contains the encoded Flash data.
Throws:
IOException - if an error occurs while decoding the data.

RegisterCopy

public RegisterCopy(int register)
Creates a RegisterCopy object with the register number.

Parameters:
register - the number of one of the Flash Player's internal registers. Must be in the range 0..255.

RegisterCopy

public RegisterCopy(RegisterCopy object)
Creates and initialises a RegisterCopy action using the values copied from another RegisterCopy action.

Parameters:
object - a RegisterCopy action from which the values will be copied.
Method Detail

getNumber

public int getNumber()
Returns the number of the Player register that the value on the stack will be copied to.

Returns:
the register number.

copy

public RegisterCopy copy()
Creates a complete copy of this object.

Specified by:
copy in interface Copyable<Action>
Returns:
a deep-copy of this object. New instances of mutable objects are copied and immutable instances are shared.

toString

public String toString()

Overrides:
toString in class Object

prepareToEncode

public int prepareToEncode(Context context)
Prepare an object for encoding, returning the expected size of an object when it is encoded. This method also used to initialise variables, such as offsets and flags that will be used when the object is encoded. Generally the method returns the size in bytes, however when called on objects that use bit fields such as shapes the methods will return the size in bits.

Specified by:
prepareToEncode in interface SWFEncodeable
Parameters:
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Returns:
the size of the object when it is encoded.

encode

public void encode(SWFEncoder coder,
                   Context context)
            throws IOException
Encode an object to the Flash binary format.

Specified by:
encode in interface SWFEncodeable
Parameters:
coder - an SWFEncoder object.
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Throws:
IOException - if an error occurs while encoding the object.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.