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. Buttons were the first place a movie could hold actions, from SWF 1. 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 |
0000113A BF 08 2A 00 00 00 06 00 00 0A 00 0F 05 00 01 00
0000114A 00 04 00 17 00 04 00 96 03 00 00 30 00 96 03 00
0000115A 00 30 00 96 02 00 00 00 27 00 00 00 08 00 28 00
0F, all four states) showing character 5 at depth 1 with an empty
matrix and colour transform; then a condition action of 23 bytes on
OverUpToOverDown, which pushes “0”, “0” and “” and runs ActionStartDrag; and the last,
on OverDownToOverUp, ActionEndDragIn ActionScript that is on (press) { startDrag(""); } and
on (release) { stopDrag(); }: a button that drags the clip it is in.
BUTTONRECORD
| Type | Name | Meaning |
|---|---|---|
| UB[4] | ButtonReserved | 0 (later formats use the last two bits for blend modes and filters) |
| 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 |
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. In the example, 04 00 is
OverUpToOverDown and 08 00 OverDownToOverUp.
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 |
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 |