views:

49

answers:

2

I need to create an extension of a Flex component, which (obviously) means that the new component should be able to be used whenever the parent is used. But I don't see the way to do it, Flex offers two ways of extending a component, by defining an AS class extending the parent or by creating an MXML file that uses the parent component as a root element; in both cases I can’t use nested elements to configure the child as I do for parent.

E. G.

package components {
import mx.controls.AdvancedDataGrid;

public class FixedDataGrid extends AdvancedDataGrid {
    public function FixedDataGrid() {
        super();
    }
}
}

This is Valid MXML

 <mx:AdvancedDataGrid>

...

    <mx:columns>

...

This is NOT Valid MXML

<mx:FixedDataGrid>
...
<mx:columns>
...

It doesn't seem like a valid is-a relation.

+3  A: 

Your FixedDataGrid doesn't exist in the same namespace as the mx components...

you need to specify the correct namespace for it to be legal.

<mx:Application xmlns:components="components.*" ... >
<components:FixedDataGrid>
    ....

You are doing the mxml equivalent of declaring your component in the components package then complaining you can't reference it as mx.controls.FixedDataGrid

Gregor Kiddie
Sorry, I just didn't reproduced my code accurately. I actually have xmlns:custom="components.*" and <custom:FixedDataGrid> but it doesn't solve the problem.
Tony
is your problem with the columns? They need to exist in the same namespace as their parent so they would be declared as<components:columns>
Gregor Kiddie
+1  A: 

When defining properties via a new MXMLtag, the property must contain be specified in the same namespace as the tag.

So you could do something like this:

<myComp:FixedDataGrid columns="SomeArray">

Without any issues. If you use the MXML tag syntax to define the columns array property, you need to do this:

<myComp:FixedDataGrid >
 <myComp:columns>
  <mx:AdvancedDataGridColumn />
  <mx:AdvancedDataGridColumn />
 </myComp:columns>
</myComp:FixedDataGrid >

columns is a property on the AdvancedDataGrid, and therefore must be defined in the same namespace as your custom extension to the AdvancedDataGrid. AdvancedDataGridColumn is a different component, so it would be definined in the mx namespace.

As mentioned by an alternate poster, the 'myComp' namespace must be defined in the top level component of your application. Most of the time Flash Builder will add the namespace automatically for you.

www.Flextras.com
Thanks! Your answer was very helpful, that solved the problem.
Tony
Great, don't forget to accept my answer as having solved your problem.
www.Flextras.com