AS2 & OOP: Extend a class or component

This is a general question regarding OOP in AS2.

I know that it is possibl to extend a class or a component with a new class that uses the 'extends' keyword in the class constructor. However, what is not clear to me is whether all the properties and methods in the original class or components have to be redefined in order to use them or whether they just simply work the way they should, unless I override them.

Well, some early tests I did with components caused some issues, which left the extend class not to work at all.

Can someone shed some light on the topic?

What is the best approach to extending an existing class or component?


Who is Participating?
By extending an existing class, you inherently still have access to the existing functionality of that class/component. Below are a few pointers to help you...

1. A flash component consits of a class file and an component movie clip. These must have the same name.
2. You can assign multiple classes per component.
3. You can refer to (by instantiating other classes from your new class) using "import [package name][class name]" before the start of the class definition, to use their functionality.
4. For a visual component you need to extend the UIComponent generic class. Or you can extend specific components (textinput, check box etc). Remember, this only needs to be the case if you want your component to use the existing class functionality provided. If you are creating an entirely new component -then you do not need to extend anything!
5. When you have created a class and a component, you need to set the Linkage indentifier of the MC to the component class. Also in the AS 2.0 box, type the full path pf your component class.
6. Right click on the movie clip in library, and chose Component Definitions. In the AS 2.0 box, add the full path of the class. This tells the movie clip to become a component, and what class to use to control its behaviour.

Note: I refer to "package", this is simply a directory you can create, often relative to your swf.

There alot to talke about regarding components and classes. Most of which is beyond the scope of this answer. But I hope some of this helps. :)

Aneesh ChopraCommented:
Here I just replying on your point,

Extending a class means, new class will have all properties/methods of the extended class available for use.
no need to redefined it.

yes, you can override any property/method by defining it again in the new class...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.