Specifications
264 ActionScript: Work with Objects and Classes
The Drag class now inherits all properties and methods from the existing
MovieClip class, and you can use MovieClip properties and methods
anywhere within the class definition, as in the following example:
class Drag extends MovieClip
{
// constructor
function Drag ()
{
onPress=doDrag;
onRelease=doDrop;
}
private function doDrag():Void
{
this.startDrag();
}
private function doDrop():Void
{
this.stopDrag();
}
}
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.
NOTE
The following ActionScript is an example only. Do not enter the script in
your lesson FLA file.
NOTE
The Convert to Symbol dialog box now offers a class field in which you
can associate visual objects (such as movie clip) with any class that you
define in ActionScript 2.0.