A button is a character with four states, up, over, down and hit test, each drawn with other characters, and with actions that run when the mouse or a key changes its state. The hit test state is the clickable area and is never drawn. The explorer draws a button in its up state.
DefineButton (7)
| Type | Name | Meaning |
|---|---|---|
| UI16 | ButtonId | The character ID |
| BUTTONRECORD[] | Characters | The characters of each state |
| UI8 | CharacterEndFlag | 0 |
| ACTIONRECORD[] | Actions | Actions, ending with an End action |
The actions run when the button is released: pressed and released over it. Its records have no colour transform; DefineButtonCxform gives one for the whole button.
DefineButton2 (34, SWF 3)
| Type | Name | Meaning |
|---|---|---|
| UI16 | ButtonId | The character ID |
| UB[7] | ReservedFlags | 0 |
| UB[1] | TrackAsMenu | Track as a menu: other buttons react while the mouse is held down |
| UI16 | ActionOffset | From this field to the first condition action; 0 for none |
| BUTTONRECORD[] | Characters | With colour transforms |
| UI8 | CharacterEndFlag | 0 |
| BUTTONCONDACTION[] | Actions | Actions for state changes |
BUTTONRECORD
| Type | Name | Meaning |
|---|---|---|
| UB[2] | ButtonReserved | 0 |
| UB[1] | ButtonHasBlendMode | A blend mode follows (SWF 8) |
| UB[1] | ButtonHasFilterList | A filter list follows (SWF 8) |
| UB[1] | ButtonStateHitTest | Part of the hit area |
| UB[1] | ButtonStateDown | Shown when pressed |
| UB[1] | ButtonStateOver | Shown when the mouse is over it |
| UB[1] | ButtonStateUp | Shown normally |
| UI16 | CharacterID | The character to show |
| UI16 | PlaceDepth | Its depth inside the button |
| MATRIX | PlaceMatrix | Its position |
| CXFORMWITHALPHA | ColorTransform | DefineButton2 only |
| FILTERLIST | FilterList | DefineButton2, if ButtonHasFilterList |
| UI8 | BlendMode | DefineButton2, if ButtonHasBlendMode |
BUTTONCONDACTION
| Type | Name | Meaning |
|---|---|---|
| UI16 | CondActionSize | The bytes in this record; 0 for the last |
| UB[1] | CondIdleToOverDown | Held down elsewhere and moved over it, with menu tracking |
| UB[1] | CondOutDownToIdle | Released outside |
| UB[1] | CondOutDownToOverDown | Held down and moved back in |
| UB[1] | CondOverDownToOutDown | Held down and moved out |
| UB[1] | CondOverDownToOverUp | Released over it |
| UB[1] | CondOverUpToOverDown | Pressed |
| UB[1] | CondOverUpToIdle | The mouse left |
| UB[1] | CondIdleToOverUp | The mouse came over it |
| UB[7] | CondKeyPress | A key code (SWF 4); 0 for none |
| UB[1] | CondOverDownToIdle | Held down over it and moved out, with menu tracking |
| ACTIONRECORD[] | Actions | Ending with an End action |
Read as a little-endian UI16, the conditions are: IdleToOverUp 0x01, OverUpToIdle 0x02, OverUpToOverDown 0x04, OverDownToOverUp 0x08, OverDownToOutDown 0x10, OutDownToOverDown 0x20, OutDownToIdle 0x40, IdleToOverDown 0x80, OverDownToIdle 0x100, and the key code is the value >> 9.
What on (…) compiles to
| ActionScript | Condition |
|---|---|
on (rollOver) | IdleToOverUp |
on (rollOut) | OverUpToIdle |
on (press) | OverUpToOverDown |
on (release) | OverDownToOverUp |
on (releaseOutside) | OutDownToIdle |
on (dragOver) | OutDownToOverDown, and IdleToOverDown |
on (dragOut) | OverDownToOutDown, and OverDownToIdle |
on (keyPress "…") | CondKeyPress |
This is the usual mapping, as decompilers such as Flasm and JPEXS use it; the specification names only the state changes.
Key codes
| Code | Key | Code | Key |
|---|---|---|---|
| 1 | Left arrow | 14 | Up arrow |
| 2 | Right arrow | 15 | Down arrow |
| 3 | Home | 16 | Page up |
| 4 | End | 17 | Page down |
| 5 | Insert | 18 | Tab |
| 6 | Delete | 19 | Escape |
| 8 | Backspace | 32 to 126 | The ASCII character |
| 13 | Enter |
Clip actions with the KeyPress event use the same codes in their KeyCode byte.
DefineButtonCxform (23, SWF 2)
| Type | Name | Meaning |
|---|---|---|
| UI16 | ButtonId | A DefineButton |
| CXFORM | ButtonColorTransform | The colour transform for every state |
DefineButtonSound (17, SWF 2)
| Type | Name | Meaning |
|---|---|---|
| UI16 | ButtonId | The button |
| UI16, SOUNDINFO | ButtonSoundChar0, ButtonSoundInfo0 | OverUpToIdle: a sound ID (0 none) and, if not 0, its SOUNDINFO |
| UI16, SOUNDINFO | ButtonSoundChar1, ButtonSoundInfo1 | IdleToOverUp |
| UI16, SOUNDINFO | ButtonSoundChar2, ButtonSoundInfo2 | OverUpToOverDown |
| UI16, SOUNDINFO | ButtonSoundChar3, ButtonSoundInfo3 | OverDownToOverUp |