metadata就是元数据,反应一个类本质的属性,可以通过describeType(obj)来得到反应该对象的xml.
要自定义元数据,如[MyMatedata()]:
package {
public class MyClass extends Object{
[MyMatedata(name = " ha " ,name2 = " haha2 " )]
public var a:String;
public function MyClass(){
super();
}
public function getA(): void {
trace( " dd " );
}
}
public class MyClass extends Object{
[MyMatedata(name = " ha " ,name2 = " haha2 " )]
public var a:String;
public function MyClass(){
super();
}
public function getA(): void {
trace( " dd " );
}
}
}
describeType(new MyClass())返回:
<
type
name
="MyClass"
base
="Object"
isDynamic
="false"
isFinal
="false"
isStatic
="false"
>
< extendsClass type ="Object" />
< variable name ="a" type ="String" >
< metadata name ="MyMatedata" > ---------------------------------->自定义元数据
< arg key ="name" value ="ha" />
< arg key ="name2" value ="haha2" />
</ metadata >
< metadata name ="__go_to_definition_help" >
< arg key ="pos" value ="108" />
</ metadata >
</ variable >
< method name ="getA" declaredBy ="MyClass" returnType ="void" >
< metadata name ="__go_to_definition_help" >
< arg key ="pos" value ="189" />
</ metadata >
</ method >
< metadata name ="__go_to_ctor_definition_help" >
< arg key ="pos" value ="137" />
</ metadata >
< metadata name ="__go_to_definition_help" >
< arg key ="pos" value ="26" />
</ metadata >
</type>
< extendsClass type ="Object" />
< variable name ="a" type ="String" >
< metadata name ="MyMatedata" > ---------------------------------->自定义元数据
< arg key ="name" value ="ha" />
< arg key ="name2" value ="haha2" />
</ metadata >
< metadata name ="__go_to_definition_help" >
< arg key ="pos" value ="108" />
</ metadata >
</ variable >
< method name ="getA" declaredBy ="MyClass" returnType ="void" >
< metadata name ="__go_to_definition_help" >
< arg key ="pos" value ="189" />
</ metadata >
</ method >
< metadata name ="__go_to_ctor_definition_help" >
< arg key ="pos" value ="137" />
</ metadata >
< metadata name ="__go_to_definition_help" >
< arg key ="pos" value ="26" />
</ metadata >
</type>
这样就可以通过给类添加元数据从而进行编码活动,基于元数据的编程很多时候被忽视,但是使用元数据有时候会很方便,尤其是在做AS3反射,和写框架的时候.
describeType 实现actionscript语言的反射,这样通过元数据可以进行更多的编程.
在使用自定义元数据时,需要在flex sdk的编译参数里面添加.
-keep-as3-metadata+=MyMetadata
注意是+= ,如果写成=就会覆盖很多原生自带的元数据标签,从而导致出问题
转自:http://sswilliam.blog.163.com/blog/static/18969638320116103225397/