120
Chapter 15: Work with Objects and Classes Using ActionScript 2.0
Extend the MovieClip class to create a new class
You’ll create a new class by extending the built-in MovieClip class.
1.
Create a new Flash document and name it Shape.fla.
2.
Using the drawing tools, draw a shape on the Stage. With the entire shape selected, right-click
(Windows) or Control-click (Macintosh) the shape and select Convert to Symbol from the
context menu.
3.
In the Convert to Symbol dialog box, select Movie Clip as the behavior, and click Advanced.
Select Export for ActionScript.
4.
In the Name text box, enter
myShape
.
5.
In the AS 2.0 Class text box, enter
Drag
. Click OK.
This associates the movie clip with the Drag class that you’ll create.
6.
Using the Property inspector, assign the movie clip an instance name. Then save the FLA file.
Note:
An example finished file of the document you just created, named handson3.fla, is located in
your finished files folder. For the path, see
“Set up your workspace” on page 113
.
7.
Create an ActionScript file by doing one of the following:
■
If you’re using Flash MX 2004 Professional, select File > New > ActionScript File (Not Flash
Document). Save the document with the name Drag, in the same location where you saved
Shape.fla.
■
If you’re using Flash MX 2004, open a text editor, such as Notepad. Save the file with the
name Drag.as, in the same location where you saved Shape.fla.
8.
In the ActionScript file that you just created, create a new class and constructor called
Drag
:
class Drag extends MovieClip
{
function Drag ()
{
onPress=doDrag;
onRelease=doDrop;
}
}
Summary of Contents for FLASH MX 2004-LEARNING FLASH
Page 1: ...Learning Flash...
Page 8: ...8 Contents...
Page 34: ...34 Chapter 3 Write Scripts with ActionScript...
Page 54: ...54 Chapter 6 Create a User Interface with Layout Tools...
Page 62: ...62 Chapter 7 Draw in Flash...
Page 68: ...68 Chapter 8 Create Symbols and Instances...
Page 76: ...76 Chapter 9 Add Animation and Navigation to Buttons...
Page 104: ...104 Chapter 13 Add Interactivity with ActionScript...
Page 112: ...112 Chapter 14 Create a Form with Conditional Logic and Send Data...
Page 122: ...122 Chapter 15 Work with Objects and Classes Using ActionScript 2 0...