AS2 & OOP: Extend a class or component

Posted on 2006-03-21
Last Modified: 2008-01-16
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?


Question by:jsound
    LVL 2

    Accepted Solution

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

    LVL 34

    Expert Comment

    by:Aneesh Chopra
    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...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
    Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
    The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now