« Stream from any point in a FLV using PHP | Main | Skinning the Flash DataGrid (Part 2) »

Extending the Macromedia V2 Components

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.

A word from our sponsors :)

Comments

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!

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?

One would not normally add the dataprovider to the extended class? I am just extending to add functionality that isn't already in the DataGrid. Both setting the size and the dataprovider is there already? Here is how I set the size and dataprovider in my FLA (not the extended class):

var myDP_array:Array = new Array();
myDP_array.push({name:"Clark",checked:false, score:3135});
myDP_array.push({name:"Bruce",checked:true, score:403});
myDP_array.push({name:"Peter",checked:false, score:25});
my_dg.dataProvider = myDP_array;
my_dg.setSize(250, 200);

Hope that helps?

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

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

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)