Search code examples
actionscript-3flashapache-flexflex4

Is there a way to get the DefaultProperty metadata at runtime?


I'm trying to get the DefaultProperty metadata for a class in ActionScript but I can't find any mention of the DefaultProperty in the metadata XML.

I'm using the following code:

var describedTypeRecord:DescribeTypeCacheRecord = mx.utils.DescribeTypeCache.describeType(BorderContainer);
var typeDescription:* = describedTypeRecord.typeDescription;

The XML is long but here the first node it returns:

<type name="spark.components::BorderContainer" base="spark.components::SkinnableContainer" isDynamic="false" isFinal="false" isStatic="false">

The default property for BorderContainer or SkinnableContainer is mxmlContentFactory:

[DefaultProperty("mxmlContentFactory")]

I've also tried RichText. The default property for this is "content":

[DefaultProperty("content")]

It doesn't seem to show anything about it in the metadata.

In the compiler options I have included the compiler arguments:

-keep-as3-metadata+=DefaultProperty

Solution

  • It is not set on some classes but if it is defined it will be defined on the super classes.

    I was checking BorderContainer but it was defined on a SkinnableContainer:

    <metadata name="DefaultProperty">
      <arg key="" value="mxmlContentFactory"/>
    </metadata>
    

    The code I have posted works when it's defined on the main class. If a class doesn't have a default property I would get a list of all the super classes and check each one until I got to object or UIComponent.