com.flagstone.transform.action
Class NewFunction

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

public final class NewFunction
extends Object
implements Action

The NewFunction action is used to create a user-defined function.

User-defined functions are also used to create methods for user-defined objects. The name of the function is omitted and the function definition is assigned to a variable which allows it to be referenced at a later time.

In the actions which form the function body all the arguments passed to the function can be referenced by the name supplied in the arguments list.

All the action objects created are owned by the function. They will be deleted when the function definition is deleted.

See Also:
NewFunction2

Nested Class Summary
static class NewFunction.Builder
          The Builder class is used to generate a new NewFunction object using a small set of convenience methods.
 
Constructor Summary
NewFunction(List<String> argumentArray, List<Action> actionArray)
          Creates a anonymous NewFunction with the specified argument names and actions to be executed.
NewFunction(NewFunction.Builder builder)
          Creates and initialises a NewFunction object using parameters defined in the Builder.
NewFunction(NewFunction object)
          Creates and initialises a NewFunction action using the values copied from another NewFunction action.
NewFunction(String aString, List<String> argumentArray, List<Action> actionArray)
          Creates a NewFunction with the specified name, argument names and actions to be executed.
NewFunction(SWFDecoder coder, Context context)
          Creates and initialises a NewFunction definition using values encoded in the Flash binary format.
 
Method Summary
 NewFunction copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 List<Action> getActions()
          Get the actions that will be executed.
 List<String> getArguments()
          Get the names of the function arguments.
 String getName()
          Get the name of the function.
 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

NewFunction

public NewFunction(NewFunction.Builder builder)
Creates and initialises a NewFunction object using parameters defined in the Builder.

Parameters:
builder - a Builder object containing the parameters to generate the function definition.

NewFunction

public NewFunction(SWFDecoder coder,
                   Context context)
            throws IOException
Creates and initialises a NewFunction definition using values encoded in the Flash binary format.

Parameters:
coder - an SWFDecoder object that contains the encoded Flash data.
context - a Context object used to manage the decoders for different type of object and to pass information on how objects are decoded.
Throws:
IOException - if an error occurs while decoding the data.

NewFunction

public NewFunction(String aString,
                   List<String> argumentArray,
                   List<Action> actionArray)
Creates a NewFunction with the specified name, argument names and actions to be executed. The order of the Strings in the argument list indicate the order in which the values will be popped off the stack when the function is executed. The fist argument is popped from the stack first.

Parameters:
aString - the name of the function. May not be null.
argumentArray - the list of Strings giving the names of the arguments.
actionArray - the list of actions that define the operation performed by the function.

NewFunction

public NewFunction(List<String> argumentArray,
                   List<Action> actionArray)
Creates a anonymous NewFunction with the specified argument names and actions to be executed. Use this constructor when defining functions that will be assigned to object variables and used as methods.

Parameters:
argumentArray - a list of Strings giving the names of the arguments.
actionArray - a list of actions that define the operation performed by the function.

NewFunction

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

Parameters:
object - a NewFunction action from which the values will be copied. References to immutable objects will be shared.
Method Detail

getName

public String getName()
Get the name of the function. If the function will be used as an object method then the name is an empty string.

Returns:
the name of the function or an empty string.

getArguments

public List<String> getArguments()
Get the names of the function arguments.

Returns:
a list of argument names in the order they appear in the function definition.

getActions

public List<Action> getActions()
Get the actions that will be executed.

Returns:
the actions that define the function behaviour.

copy

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