com.flagstone.transform.action
Class If

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

public final class If
extends Object
implements Action

The If action is used to perform a conditional branch to control the actions executed by the Flash Player.

When executed, the If action pops a value from the stack and evaluates it to see whether it evaluates as true or false. If the boolean value is true the offset attribute of the If action is added to the Flash Player's instruction pointer and execution of the stream of actions continues from that location. If the boolean value is false then no branch is taken.

Although the Flash Player contains an instruction pointer it does not support an explicit address space. The instruction pointer is used to reference actions within the current stream of actions being executed whether they are associated with a given frame, button or movie clip. The value contained in the instruction pointer is the address relative to the start of the current stream.

The offset is a signed number, allowing branches up to -32768 to 32767 bytes. The instruction pointer points to the next instruction in the stream of actions being executed so specifying an offset of zero will have no effect on the sequence of instructions executed.

If the value popped off the stack is a number it is evaluated as true if it is non-zero. If the value is a string it is evaluated to true if it is not an empty string ("") or the strings "0" or "false".

See Also:
Jump

Constructor Summary
If(If object)
          Creates and initialises an If action using the values copied from another If action.
If(int anOffset)
          Creates an if action with the specified offset.
If(SWFDecoder coder)
          Creates and initialises an If action using values encoded in the Flash binary format.
 
Method Summary
 If copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 int getOffset()
          Get the offset that will be added to the instruction pointer if the value at the top of the stack evaluates to true (non-zero).
 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

If

public If(SWFDecoder coder)
   throws IOException
Creates and initialises an If 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.

If

public If(int anOffset)
Creates an if action with the specified offset. The offset must be in the range -32768..32767.

Parameters:
anOffset - the number of bytes to add to the instruction pointer if the value popped off the stack evaluates to true.

If

public If(If object)
Creates and initialises an If action using the values copied from another If action.

Parameters:
object - an If action from which the values will be copied.
Method Detail

getOffset

public int getOffset()
Get the offset that will be added to the instruction pointer if the value at the top of the stack evaluates to true (non-zero).

Returns:
the offset to the next action.

copy

public If 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.