Although a lot of Flash designers add the actionscript code directly on the button I don't advise that method for the following reason : In a big project it is best to centralize the code as much as possible, either in external *.as files or more commonly on a defined frame on the main timeline. If you add the code directly on your buttons and if you have many of them it can get tedious to hunt for the buttons, especially if there is more than one developer working on the same file.
Now, let's say we want to trace "Hello" when the user presses the button :
Case 1 : we want to place the code directly on the button :
select the button and press F9 to open the actionscript window then enter the following code :
| on(release){ trace("Hello"); } |
Case 2 : we want to place the code on the main timeline where the instance of the button resides :
select the first frame of the timeline where the button resides, press F9 to open the actionscript window then enter the following code :
myButton.onRelease = function(){ |
The following table lists button events and corresponding button event methods:
| Event | Event method |
| on (press) | onPress |
| on (release) | onRelease |
| on (releaseOutside) | onReleaseOutside |
| on (rollOver) | onRollOver |
| on (rollOut) | onRollOut |
| on (dragOver) | onDragOver |
| on (dragOut) | onDragOut |
| on (keyPress "...") | onKeyDown, onKeyUp |
You can experiment with these different events and event methods.
Hopefully you should now be able to be comfortable with the creation of buttons in Flash. If you are looking for a quick way to generate smart and easily customizable buttons in Flash be sure to check our Flash 8 aqua buttons component.
Good luck :)