com.flagstone.transform
Class FSDefineButton2

java.lang.Object
  extended by com.flagstone.transform.FSTransformObject
      extended by com.flagstone.transform.FSMovieObject
          extended by com.flagstone.transform.FSDefineObject
              extended by com.flagstone.transform.FSDefineButton2
All Implemented Interfaces:
java.lang.Cloneable

public class FSDefineButton2
extends FSDefineObject

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

It provides a more sophisticated model for creating buttons:

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.

Attributes
type Identifies the data structure when it is encoded. Read-only.
identifier An unique identifier for this object in the range 1..65535.
buttonType Whether the button is a Push button or a Menu button.
buttonRecords An array of FSButton objects that describe the appearance of the button in each of its states.
buttonEvents An array of FSButtonEvent objects that define the actions that are executed for each type of button event.
encodedEvents An array of bytes containing encoded button events can also be set. The encoded objects are typically generated by the parser in the Translate framework. The buttonEvents array and encodedEvents cannot both be valid at the same time. Accessor methods used to set either of the attributes will set the other to null.

An FSDefineButton2 object must contain at least one FSButton object. If more than one button record 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.

Each FSButton object can contain an FSColorTransform object which can be used to change the colour of the shape being displayed without changing the original definition.

Actions do not need to be specified for every button event. Indeed actions do not need to be specified at all.

Examples

1. Define a button that highlights itself when the mouse is move over it and actions are executed when the button is clicked.
 FSDefineShape upShape = new FSDefineShape(movie.newIdentifier(), bounds,
                                fillStyles, lineStyles, shape1);
 FSDefineShape overShape = new FSDefineShape(movie.newIdentifier(), bounds,
                                fillStyles, lineStyles, shape2);
 FSDefineShape downShape = new FSDefineShape(movie.newIdentifier(), bounds,
                                fillStyles, lineStyles, shape3);
 
 ArrayList records = new ArrayList();
 ArrayList events = new ArrayList();
 
 records.add(FSButtonRecord(FSButton.Up, upShape.getIdentifier(), 1));
 records.add(FSButtonRecord(FSButton.Over, overShape.getIdentifier(), 2));
 records.add(FSButtonRecord(FSButton.Down, downShape.getIdentifier(), 3));
 
 ArrayList actions = new ArrayList();
 
 actions.add(action);
 actions.add(action);
 actions.add(action);
 
 events.add(FSButtonEvent(FSButtonEvent.Press, actions));
 
 FSDefineButton2 button = new FSDefineButton2(movie.newIdentifier(),
                                FSDefineButton2.Push, records, events);
 

History

The FSDefineButton2 class represents the DefineButton2 structure from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 3.


Field Summary
static int Menu
          Defines whether a FSDefineButton2 object is configured as a menu button.
static int Push
          Defines whether a FSDefineButton2 object is configured as a momentary, push button.
 
Fields inherited from class com.flagstone.transform.FSDefineObject
identifier
 
Fields inherited from class com.flagstone.transform.FSMovieObject
ButtonColorTransform, ButtonSound, DefineBitsPtr, DefineButton, DefineButton2, DefineFont, DefineFont2, DefineImage, DefineImage2, DefineJPEGImage, DefineJPEGImage2, DefineJPEGImage3, DefineMorphShape, DefineMovieClip, DefineShape, DefineShape2, DefineShape3, DefineSound, DefineText, DefineText2, DefineTextField, DefineVideo, DoAction, EnableDebugger, EnableDebugger2, Export, extendLength, FontInfo, FontInfo2, FrameLabel, Free, Import, Initialize, JPEGTables, length, LimitScript, PathsArePostscript, PlaceObject, PlaceObject2, Protect, QuicktimeMovie, RemoveObject, RemoveObject2, SerialNumber, SetBackgroundColor, ShowFrame, SoundStreamBlock, SoundStreamHead, SoundStreamHead2, StartSound, TabOrder, type, VideoFrame
 
Constructor Summary
FSDefineButton2(FSCoder coder)
          Construct an FSDefineButton2 object, initialising it with values decoded from an encoded object.
FSDefineButton2(FSDefineButton2 obj)
          Constructs an FSDefineButton2 object by copying values from an existing object.
FSDefineButton2(int anIdentifier, int buttonType, java.util.ArrayList buttonRecordArray, java.util.ArrayList buttonEventArray)
          Constructs an FSDefineButton object, specifying the unique identifier, the type of button to be created, the button records that describe the button's appearance and the actions that are performed in response to each button event.
FSDefineButton2(int anIdentifier, int buttonType, java.util.ArrayList buttonRecordArray, byte[] bytes)
          Constructs an FSDefineButton object, specifying the unique identifier, the type of button to be created, the button records that describe the button's appearance and the encoded actions that are performed in response to each button event.
 
Method Summary
 void add(FSButton aButton)
          Adds an FSButton to the array of button records.
 void add(FSButtonEvent aButtonEvent)
          Adds a button event object to the array of button events.
 void appendDescription(java.lang.StringBuffer buffer, int depth)
          AppendDescription is used to present a string description of the object including all nested objects up to a specified depth.
 java.lang.Object clone()
          Creates a deep copy of the entire object.
 void decode(FSCoder coder)
           
 void encode(FSCoder coder)
           
 boolean equals(java.lang.Object anObject)
          Returns true if anObject is equal to this one.
 java.util.ArrayList getButtonEvents()
          Gets the array of button records defined for this button.
 java.util.ArrayList getButtonRecords()
          Gets the array of button records defined for this button.
 int getButtonType()
          Gets the button type - push or menu.
 int length(FSCoder coder)
           
 void setButtonEvents(java.util.ArrayList anArray)
          Sets the array of button events defined for this button.
 void setButtonRecords(java.util.ArrayList anArray)
          Sets the array of button records defined for this button.
 void setButtonType(int aType)
          Sets the button type.
 void setEncodedEvents(byte[] bytes)
          Set the encoded button event objects generated by the classes in the Translate framework.
 
Methods inherited from class com.flagstone.transform.FSDefineObject
getIdentifier, setIdentifier
 
Methods inherited from class com.flagstone.transform.FSMovieObject
getType
 
Methods inherited from class com.flagstone.transform.FSTransformObject
name, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

Push

public static final int Push
Defines whether a FSDefineButton2 object is configured as a momentary, push button.

See Also:
Constant Field Values

Menu

public static final int Menu
Defines whether a FSDefineButton2 object is configured as a menu button.

See Also:
Constant Field Values
Constructor Detail

FSDefineButton2

public FSDefineButton2(FSCoder coder)
Construct an FSDefineButton2 object, initialising it with values decoded from an encoded object.

Parameters:
coder - an FSCoder containing the binary data.

FSDefineButton2

public FSDefineButton2(int anIdentifier,
                       int buttonType,
                       java.util.ArrayList buttonRecordArray,
                       java.util.ArrayList buttonEventArray)
Constructs an FSDefineButton object, specifying the unique identifier, the type of button to be created, the button records that describe the button's appearance and the actions that are performed in response to each button event.

Parameters:
anIdentifier - a unique identifier for this button.
buttonType - the type of button - push or menu.
buttonRecordArray - an array of FSButton objects.
buttonEventArray - an array of FSButtonEvent objects.

FSDefineButton2

public FSDefineButton2(int anIdentifier,
                       int buttonType,
                       java.util.ArrayList buttonRecordArray,
                       byte[] bytes)
Constructs an FSDefineButton object, specifying the unique identifier, the type of button to be created, the button records that describe the button's appearance and the encoded actions that are performed in response to each button event.

Parameters:
anIdentifier - a unique identifier for this button.
buttonType - the type of button - push or menu.
buttonRecordArray - an array of FSButton objects.
bytes - an array containing the encoded FSButtonEvent objects.

FSDefineButton2

public FSDefineButton2(FSDefineButton2 obj)
Constructs an FSDefineButton2 object by copying values from an existing object.

Parameters:
obj - an FSDefineButton2 object.
Method Detail

add

public void add(FSButton aButton)
Adds an FSButton to the array of button records.

Parameters:
aButton - a button record.

add

public void add(FSButtonEvent aButtonEvent)
Adds a button event object to the array of button events.

Parameters:
aButtonEvent - a button event.

getButtonType

public int getButtonType()
Gets the button type - push or menu.

Returns:
the type of button.

getButtonRecords

public java.util.ArrayList getButtonRecords()
Gets the array of button records defined for this button.

Returns:
the array of button records.

getButtonEvents

public java.util.ArrayList getButtonEvents()
Gets the array of button records defined for this button.

Returns:
the array of button events.

setButtonType

public void setButtonType(int aType)
Sets the button type.

Parameters:
aType - the type of button - push or menu.

setButtonRecords

public void setButtonRecords(java.util.ArrayList anArray)
Sets the array of button records defined for this button.

Parameters:
anArray - an array of FSButtonRecord objects.

setButtonEvents

public void setButtonEvents(java.util.ArrayList anArray)
Sets the array of button events defined for this button. If the object contains encodedEvents then they will be deleted.

Parameters:
anArray - and array of FSButtonEvent objects.

setEncodedEvents

public void setEncodedEvents(byte[] bytes)
Set the encoded button event objects generated by the classes in the Translate framework. If the object already contains an array of button events objects then they will be deleted.

Parameters:
bytes - the array of encoded button events.

clone

public java.lang.Object clone()
Description copied from class: FSTransformObject
Creates a deep copy of the entire object.

Overrides:
clone in class FSTransformObject
Returns:
a copy of the object.

equals

public boolean equals(java.lang.Object anObject)
Description copied from class: FSMovieObject
Returns true if anObject is equal to this one. Objects are considered equal if they would generate identical binary data when they are encoded to a Flash file.

Overrides:
equals in class FSMovieObject
Returns:
true if this object would be identical to anObject when encoded.

appendDescription

public void appendDescription(java.lang.StringBuffer buffer,
                              int depth)
Description copied from class: FSTransformObject
AppendDescription is used to present a string description of the object including all nested objects up to a specified depth. This method provide a more controlled way of creating a string representation of an object since large objects such as font or shape definitions can contain dozens of nested objects. The representation of the object is appended to the StringBuffer, showing the name of the class and values of the attributes it contains. If the object contains any attributes that are objects then the object graph will be traversed up to the specified depth. If objects are nested at a level less than specified depth then the full string representation of the object is displayed. For objects at the specified depth only the name of the class is displayed. Any objects below this depth are not displayed.

Overrides:
appendDescription in class FSDefineObject
Parameters:
buffer - a StringBuffer to which the description of each object is appended.
depth - the maximum level of nesting up to which objects will be displayed.

length

public int length(FSCoder coder)
Overrides:
length in class FSDefineObject

encode

public void encode(FSCoder coder)
Overrides:
encode in class FSDefineObject

decode

public void decode(FSCoder coder)
Overrides:
decode in class FSDefineObject