开发者

Custom metadata in AS3/Flex?

How to create and to work with custom metadata in 开发者_开发百科ActionScript3/Flex?


There is two general directions to deal with metadata in ActionScript in Flex:

  1. Dealing in runtime using reflection (or introspection in terms of Adobe). You can find documentation here. There are several third-party libraries which provides more convenient reflection API such as as3-commons-reflect or reflection API in Parsley.
  2. Using Flex Compiler Extensions which was introduced since Flex 4 SDK revision 8165 (see details). See also the corresponding discussion and official documentation.


To create metadata, just use square bracket syntax in your class definition:

[ClassAttr]
public class ClassWithMetadata {
    [AttributeNoArgs]
    public var data:Object;

    [AttributeWithArgs(arg="value)]
    public var prop:Object;
}

Call describeType(ClassWithMetadata) to get xml description of your class. Metadata will be there, you can parse it and process as you like.
To prevent compiler from stripping your metadata, add compiler argument -keep-as3-metadata Attribute for each attribute name you using. This can be done in library settings or in each project that uses metadata.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜