Custom metadata in AS3/Flex?

旧时模样 提交于 2019-12-19 13:47:22

问题


How to create and to work with custom metadata in ActionScript3/Flex?


回答1:


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.



回答2:


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.



来源:https://stackoverflow.com/questions/5729294/custom-metadata-in-as3-flex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!