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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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. :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.