Adobe Flash

Learn about extending existing classes

The extends keyword in ActionScript 2.0 allows you to use all the methods and properties of an existing class in a new class. For example, if you wanted to define a class called Drag that inherited everything from the MovieClip class, you could use the following:

class Drag extends MovieClip
{}

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:

Note

The following ActionScript is an example only. Do not enter the script in your lesson FLA file.


class Drag extends MovieClip
{

    // constructor

    function Drag ()
    {
      onPress=doDrag;
      onRelease=doDrop;
    }

    private function doDrag():Void
    {
      this.startDrag();

    }
    private function doDrop():Void
    {
      this.stopDrag();
    }
}

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.