com.flagstone.transform
Class EventHandler

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

public final class EventHandler
extends Object
implements Action

EventHandler is used to define the actions that a movie clip or button will execute in response to a particular event. Handlers for movie clips are defined when the movie clip is added to the display list using Place2 or Place3 objects while handlers for buttons are added when the button is created.

See Also:
Event

Constructor Summary
EventHandler(EventHandler object)
          Creates and initialises a EventHandler object using the values copied from another EventHandler object.
EventHandler(int value, SWFDecoder coder, Context context)
          Creates and initialises a EventHandler object using values encoded in the Flash binary format.
EventHandler(Set<Event> event, int character, List<Action> list)
          Creates an EventHandler object that defines the list of actions that will be executed when a particular event occurs or when the specified key is pressed.
EventHandler(Set<Event> event, List<Action> list)
          Creates a ClipEvent object that with a list of actions that will be executed when a particular event occurs.
 
Method Summary
 EventHandler add(Action anAction)
          Adds an action to the list of actions.
 EventHandler 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 list of actions that are executed by the movie clip.
 int getEventCode()
          Get the value that is encoded to represent the set of events that the handler responds to.
 Set<Event> getEvents()
          Get the set of events that the handler responds to.
 int getKey()
          Get the code for the key that triggers the event when pressed.
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 void setActions(List<Action> list)
          Sets the list of actions that are executed by the handler in response to specified event(s).
 void setEvents(Set<Event> set)
          Set the events that the handler responds to.
 void setKey(int code)
          Sets the code for the key that triggers the event when pressed.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EventHandler

public EventHandler(int value,
                    SWFDecoder coder,
                    Context context)
             throws IOException
Creates and initialises a EventHandler object using values encoded in the Flash binary format.

Parameters:
value - is decoded by and it is dependent on the parent object. If it is a Place2 or Place3 object then the event handler is for a movie clip and the value represents the the set of events that the handler responds to. If the parent object is a button then the value is the length in bytes of the encoded actions executed by the handler.
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.

EventHandler

public EventHandler(Set<Event> event,
                    List<Action> list)
Creates a ClipEvent object that with a list of actions that will be executed when a particular event occurs.

Parameters:
event - the set of Events that the handler will respond to.
list - the list of actions that will be executed when the specified event occurs.

EventHandler

public EventHandler(Set<Event> event,
                    int character,
                    List<Action> list)
Creates an EventHandler object that defines the list of actions that will be executed when a particular event occurs or when the specified key is pressed.

Parameters:
event - the set of Events that the handler will respond to.
character - the ASCII code for the key pressed on the keyboard.
list - the list of actions that will be executed when the specified event occurs. Must not be null.

EventHandler

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

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

getEventCode

public int getEventCode()
Get the value that is encoded to represent the set of events that the handler responds to. NOTE: This method is only used by Place2 and Place3 objects to encode EventHandlers for movie clips. It should not be used.

Returns:
the value representing the set of encoded events.

getEvents

public Set<Event> getEvents()
Get the set of events that the handler responds to.

Returns:
a set of Events.

setEvents

public void setEvents(Set<Event> set)
Set the events that the handler responds to.

Parameters:
set - the set of Events for the handler.

getKey

public int getKey()
Get the code for the key that triggers the event when pressed. The code is typically the ASCII code for standard western keyboards.

Returns:
the ASCII code for the key that triggers the event.

setKey

public void setKey(int code)
Sets the code for the key that triggers the event when pressed. The code is typically the ASCII code for standard western keyboards.

Parameters:
code - the ASCII code for the key that triggers the event.

getActions

public List<Action> getActions()
Get the list of actions that are executed by the movie clip.

Returns:
the actions executed by the handler.

setActions

public void setActions(List<Action> list)
Sets the list of actions that are executed by the handler in response to specified event(s).

Parameters:
list - the array of actions that will be executed when the specified event occurs. Must not be null.

add

public EventHandler add(Action anAction)
Adds an action to the list of actions.

Parameters:
anAction - an action object. Must not be null.
Returns:
this object.

copy

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