Yes, you can define your own metadata and access it at runtime using the
describeType() function. However, by default the only metadata that is
compiled into the SWF is [Bindable], [Managed], [ChangeEvent],
[NonCommittingChangeEvent], and [Transient] (see the <keep-as3-metadata>
section in flex-config.xml) and you must change the default value of the
keep-as3-metadata option to include other metadata into the SWF.

As an example, compile the following application

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>

    <mx:Script>
    <![CDATA[

        import flash.utils.describeType;

        [Foo(bar="baz")]
        public function doit():void
        {
        }

    ]]>
    </mx:Script>

    <mx:Button click="trace(describeType(this))"/>

</mx:Application>

with the option 

 
-keep-as3-metadata=Bindable,Managed,ChangeEvent,NonCommittingChangeEvent
,Transient,Foo

Click the button and inspect the trace output. You'll see
 
  <method name="doit" declaredBy="test1" returnType="void">
    <metadata name="Foo">
      <arg key="bar" value="baz"/>
    </metadata>
  </method>

 
Note: describeType() will only give you info about public APIs.
 
- Gordon

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Paul deCoursey
Sent: Friday, June 08, 2007 10:36 AM
To: [email protected]
Subject: [flexcoders] Metadata question



Does anybody know if it's possible to define our own metadata and access

that info at runtime? For example, I'm writing a XML-Object binding 
framework and I'd like to add some metadata to some generated classes 
that I can access at runtime. The data I'd like to add is info about 
how the object should be read or written to and from XML.

Paul



 

Reply via email to