Required attributes in MXML?

Is it possible, with some kind of metadata, to get an object property to be set? We have a few non-visual components that simply do nothing if one or more properties are set, for example:

<ToolTip target="{this}">
    <mx:Image source="foo.png" />
</ToolTip>

      

In this case, the target property will be nice to mark as needed, since there is no point in setting it. This is not a big problem as it is easy to document, but it would be nice to eliminate at least a few debugging rounds if the compiler informs the developer about his error.

We don't want this tag to be redundant in any way that could be solved (in this case) by simply making the ToolTip UIComponent and using the parent property. But, on the one hand, this adds extra overhead, and in other cases it is simply wrong:

<Button id="btn" label="Foo" />
<ToolTip target="{btn}">
    <mx:Image source="foo.png" />
</ToolTip>

      

So are mxml attributes possible?

+1


a source to share


1 answer


There is a solution, but it is not QUITE as easy as using metadata. It's just that your non-visual components implement the IMXMLObject interface. An interface has only one "initialized" method. Interface injection allows you to validate an object as being initialized through MXML.

In this way...



public function initialized(document:Object, id:String):void
{
  if ( target == null ) throw new Error( "You must supply an argument to target!" );
} 

      

It would be nice to check the compile time, but it works decently.

+1


a source







All Articles