EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 339

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Using button and movie clip event handlers 339
To use an on handler and onPress event handler:
1. Create a new Flash document and save it as handlers.fla.
2. Select the Rectangle Tool and draw a large square on the Stage.
3. Select the Selection Tool, double-click the square on the Stage, and press F8 to launch the
Convert to Symbol dialog box.
4. Enter a symbol name for the box, set the type to Movie clip and click OK.
5. Give the movie clip on the Stage an instance name of box_mc.
6. Add the following ActionScript directly on the movie clip symbol on the Stage:
on (press) {
trace("on (press) {...}");
}
7.
Add the following ActionScript to Frame 1 of the main Timeline:
box_mc.onPress = function() {
trace("box_mc.onPress = function() {...};");
};
8.
Select Control > Test Movie to test the Flash document.
When you click the movie clip symbol on the Stage, the following output is sent to the
Output panel:
on (press) {...}
box_mc.onPress = function() {...};
NOTE
Attaching onClipEvent() and on() handlers is not a recommended practice. Instead,
you should put your code in frame scripts or in a class file, as demonstrated
throughout this manual. For more information, see “Using event handler methods”
on page 330 and “Attaching code to objects” on page 746.

Table of Contents

Related product manuals