Extending the Macromedia V2 Components

22 Feb

Lesson learned: When extending the V2 components, it is not enough just to construct the new class using the “extends” keyword like this:

class my.Components.MyDataGrid extends DataGrid
{
  function MyDataGrid()
  {
    trace("MyDataGrid instance created with scope "+this);
  }
}

To successfully extend the components you will need two things. One is a set of static variables that the component structure requires. The other is some exported symbols that will be referenced in the variables.

class my.Components.MyDataGrid extends DataGrid
{
  static var symbolOwner : Object = MyDataGrid;
  static var symbolName : String = "MyDataGrid";
  function MyDataGrid()
  {
    trace("MyDataGrid instance created with scope "+this);
  }
}

“symbolName” must be the same as the export ID in your library.
“symbolOwner” should be the base name of your class.

Next, create a FLA containing the component we’re extending (DataGrid) and an empty movieClip with the identifier (Export ID) specified in “symbolName”. The symbol should also link to the AS2 class using full path: my.Components.MyDataGrid. If you’re using FlashDevelop, just add the exported SWF and select “Add to Library”.

Now your extended class is ready to do it’s job. Just add any methods you want to over-ride or any additional functionality required.

22 February 2006 at 7:18 pm

5 Responses to Extending the Macromedia V2 Components

  1. avatar photo
    Mani 22 February 2006 at 10:54 pm #

    This was a very informative post. I had been wanting to subclass V2 components before with little success.  Mine is behaving funny though.  How did you customize your MyDataGrid in the class file?  I added a dataProvider but then the datagrid was too narrow a viewing field.  I added a boundingBox_mc with little success.

    Thanks for the info!

  2. avatar photo
    Jensa 23 February 2006 at 6:36 pm #

    Hi Mani,
    I only added some extra skinning features (see my post on transparent DataGrids). Not sure if I get this right about the grid being too narrow and the Dataprovider?

    my_dg.dataProvider = myDP_array;
    my_dg.setSize(250, 200);


    Hope that helps?

  3. avatar photo
    Thomas Pearson 10 March 2006 at 12:45 am #

    Hello,
    This is very under-documented subject and I am very thankfull to you for tackling it. I am trying to extend the dateChooser component and have my subClass able to trace out it’s presence, but I’m having trouble getting ‘myDateChooser’ to show up on stage. I think my problem lies with the ‘The other is some exported symbols that will be referenced in the variables.’ part of your tutorial. Could you eloborate some on this, possiblity using the dateChooser as you example.

    Thank You, Tom

  4. avatar photo
    Jensa 17 March 2006 at 5:40 pm #

    Hi Tom,
    I don’t know about the dateChooser specifically but I’m pretty sure it the very same thing. It’s really not much more to elaborate on. Just add those two variables with the correct names (your class name) and it should work. For how to declare them, just look at how it’s done above or in the original Macromedia class “mx.controls.DateChooser”.

    J

  5. avatar photo
    Sagar Parikh 12 June 2007 at 12:11 pm #

    Very useful
    Thanks,
    Sagar Parikh

  6.