2007年4月6日星期五

Abstract Classes

Unfortunately ActionScript 3 does not support abstract classes (classes that cannot be instantiated only extended). So you cannot create your own abstract classes in Flash. However, be aware that some of the internal classes in ActionScript are internally abstract. These classes include:

As abstract classes, you cannot create instances of them directly using the new keyword.

ActionScript Code:

var myObj:InteractiveObject = new InteractiveObject(); // ERROR


However, in addition to that, in ActionScript, it also means that you cannot directly subclass these classes and create instances of those subclasses

ActionScript Code:

package {
import flash.display.DisplayObject;
public class MyDisplay extends DisplayObject{
public function MyDisplay (){
// ERROR
}
}
}


This has to do with the internal nature and how they are defined for the Player. If you attempt to subclass one of these classes and instantiate that subclass, you will get the same Argument Error that you would get if you tried to instantiate one of those classes directly.

Instead, what you would need to do is extend an internal class that already subclasses these classes. For example, if you wanted to extend DisplayObject, you could instead extend Shape, a light, internal class that is a subclass of DisplayObject.

0 评论: