AS3.0高级反射

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());

输出:

AS3.0高级反射_第1张图片

 

 

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[[email protected]()] = [email protected]();

                          break;

                  case "accessor":

                          var access : String = item.@access;

                          if((access == "readwrite") || (access == "writeonly")) {

                                   propMap[[email protected]()] = [email protected]();

                           }

                          break;

          }

}



// Output the contents of the propMap object

for (var prop:String in propMap)

{

        trace(prop, "-", propMap[prop]);

}

AS3.0高级反射_第2张图片

你可能感兴趣的:(AS3.0高级反射)