AS3.0高级反射

来源:互联网 发布:中文词性标注算法 编辑:程序博客网 时间:2024/06/03 15:56
Advanced Flash Tactics or AFTs are techniques that come from deep within the Flash Art Of War, the oldest Flash military treatise in the world. Each AFT is designed to be quickly digested,

 

在flash.utils包中,我们可以用describeType来处理反射。为了使用describeType,你将需要导入它所在包,然后调用describeType并传递任何类的实例做为参数。下面是一个快速入门的例子:

 

import flash.text.TextField;import flash.utils.describeType;        var classAsXML:XML = describeType(new TextField());trace(classAsXML.toXMLString());

输出:

 

 

var list : XMLList = classAsXML.*;var propMap : Object = new Object();var item : XML;for each (item in list) {        var itemName : String = item.name().toString();        switch(itemName) {                  case "variable":                          propMap[item.@name.toString()] = item.@type.toString();                          break;                  case "accessor":                          var access : String = item.@access;                          if((access == "readwrite") || (access == "writeonly")) {                                   propMap[item.@name.toString()] = item.@type.toString();                           }                          break;          }}// Output the contents of the propMap objectfor (var prop:String in propMap){        trace(prop, "-", propMap[prop]);}


原创粉丝点击