com.flagstone.transform.button
Class DefineButton2

java.lang.Object
  extended by com.flagstone.transform.button.DefineButton2
All Implemented Interfaces:
Copyable<MovieTag>, SWFEncodeable, DefineTag, MovieTag

public final class DefineButton2
extends Object
implements DefineTag

DefineButton2 defines the appearance and actions of push and menu buttons.

It provides a more sophisticated model for creating buttons than DefineButton:

Push and Menu buttons behave slightly differently in tracking mouse movements when the button is clicked. A Push button 'captures' the mouse so if the cursor is dragged outside of the active area of the button and the mouse click is released then the Release Outside event is still sent to the button. A Menu button does not 'capture' the mouse so if the cursor is dragged out of the active area the button returns to its 'inactive' state.

A DefineButton2 object must contain at least one ButtonShape. If more than one button shape is defined for a given button state then each shape will be displayed by the button. The order in which the shapes are displayed is determined by the layer assigned to each button record.

See Also:
ButtonShape, EventHandler

Constructor Summary
DefineButton2(DefineButton2 object)
          Creates and initialises a DefineButton2 object using the values copied from another DefineButton2 object.
DefineButton2(int uid, ButtonType buttonType, List<ButtonShape> buttonShapes, List<EventHandler> handlers)
          Creates a DefineButton2 object, specifying the unique identifier, the type of button to be created, the button shapes that describe the button's appearance and the actions that are performed in response to each button event.
DefineButton2(SWFDecoder coder, Context context)
          Creates and initialises a DefineButton2 object using values encoded in the Flash binary format.
 
Method Summary
 DefineButton2 add(ButtonShape obj)
          Adds an ButtonShape to the list of button records.
 DefineButton2 add(EventHandler obj)
          Adds a button event object to the list of button events.
 DefineButton2 copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 List<EventHandler> getEvents()
          Get the list of event handlers defined for this button.
 int getIdentifier()
          Get the unique identifier assigned to this object.
 List<ButtonShape> getShapes()
          Get the list of button records defined for this button.
 ButtonType getType()
          Get the button type - either PUSH or MENU.
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 void setEvents(List<EventHandler> list)
          Sets the list of button events defined for this button.
 void setIdentifier(int uid)
          Sets the unique identifier for an object within a given Movie.
 void setShapes(List<ButtonShape> list)
          Sets the list of button shapes defined for this button.
 void setType(ButtonType buttonType)
          Sets whether the button is a menu button or a push button.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefineButton2

public DefineButton2(SWFDecoder coder,
                     Context context)
              throws IOException
Creates and initialises a DefineButton2 object 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.

DefineButton2

public DefineButton2(int uid,
                     ButtonType buttonType,
                     List<ButtonShape> buttonShapes,
                     List<EventHandler> handlers)
Creates a DefineButton2 object, specifying the unique identifier, the type of button to be created, the button shapes that describe the button's appearance and the actions that are performed in response to each button event.

Parameters:
uid - a unique identifier for this button. Must be in the range 1..65535.
buttonType - the button is a menu button (true) or push button (false).
buttonShapes - a list of Button objects. Must not be null.
handlers - a list of ButtonEvent objects. Must not be null.

DefineButton2

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

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

getIdentifier

public int getIdentifier()
Get the unique identifier assigned to this object.

Specified by:
getIdentifier in interface DefineTag
Returns:
the unique identifier used by the Flash Player to reference this definition.

setIdentifier

public void setIdentifier(int uid)
Sets the unique identifier for an object within a given Movie.

Specified by:
setIdentifier in interface DefineTag
Parameters:
uid - a unique identifier for the object. Must be in the range 1..65535.

add

public DefineButton2 add(ButtonShape obj)
Adds an ButtonShape to the list of button records.

Parameters:
obj - a button shape object. Must not be null.
Returns:
this object.

add

public DefineButton2 add(EventHandler obj)
Adds a button event object to the list of button events.

Parameters:
obj - a button event. Must not be null.
Returns:
this object.

getType

public ButtonType getType()
Get the button type - either PUSH or MENU.

Returns:
the type that identifies the button.

getShapes

public List<ButtonShape> getShapes()
Get the list of button records defined for this button.

Returns:
the list of shapes used to draw the button.

getEvents

public List<EventHandler> getEvents()
Get the list of event handlers defined for this button.

Returns:
the event handlers for the button.

setType

public void setType(ButtonType buttonType)
Sets whether the button is a menu button or a push button.

Parameters:
buttonType - the type of button, either ButtonType.MENU or ButtonType.PUSH.

setShapes

public void setShapes(List<ButtonShape> list)
Sets the list of button shapes defined for this button.

Parameters:
list - a list of ButtonShape objects. Must not be null.

setEvents

public void setEvents(List<EventHandler> list)
Sets the list of button events defined for this button. If the object already contains encodedEvents then they will be deleted.

Parameters:
list - a list of ButtonEvent objects. Must not be null.

copy

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

Specified by:
copy in interface Copyable<MovieTag>
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.