as3 遍历公开属性的方法基本类:package {public class Resume{private var _name : String NAMEprivat
as3 遍历公开属性的方法
基本类:package {public class Resume{private var _name : String ="NAME";private var _sex : String ="SEX";private var _age : String="AGE";private var _timeArea : String="TIMEAREA";private var _company : String="COMPANY";public function Resume(){ super(); }public function get name():String{return _name;}public function get sex():String{return _sex;}public function get age():String{return _age;}public function get timeArea():String{return _timeArea;}public function get company():String{return _company;}}}
文档类:
var resume:Resume = new Resume();var xml:XML = describeType(resume);trace("xml : "+xml.toXMLString());//遍历转换xml格式的数据trace("/////////////////////////////////////////////////////////////////");for(var i:int =0;i<xml.accessor.length();i++){ trace("name :"+xml.accessor[i].@name);//获取类的属性名 trace("value : "+resume[xml.accessor[i].@name]);//获取类属性值}
打印出来的值:
<extendsClass type="Object"/>
<accessor name="timeArea" access="readonly" type="String" declaredBy="clone::Resume">
<metadata name="__go_to_definition_help">
<arg key="file" value="D:\_GameDemoTest\TestTextDemo\src\clone\Resume.as"/>
<arg key="pos" value="516"/>
</metadata>
</accessor>
<accessor name="sex" access="readonly" type="String" declaredBy="clone::Resume">
<metadata name="__go_to_definition_help">
<arg key="file" value="D:\_GameDemoTest\TestTextDemo\src\clone\Resume.as"/>
<arg key="pos" value="390"/>
</metadata>
</accessor>
<accessor name="name" access="readonly" type="String" declaredBy="clone::Resume">
<metadata name="__go_to_definition_help">
<arg key="file" value="D:\_GameDemoTest\TestTextDemo\src\clone\Resume.as"/>
<arg key="pos" value="325"/>
</metadata>
</accessor>
<accessor name="company" access="readonly" type="String" declaredBy="clone::Resume">
<metadata name="__go_to_definition_help">
<arg key="file" value="D:\_GameDemoTest\TestTextDemo\src\clone\Resume.as"/>
<arg key="pos" value="589"/>
</metadata>
</accessor>
<accessor name="age" access="readonly" type="String" declaredBy="clone::Resume">
<metadata name="__go_to_definition_help">
<arg key="file" value="D:\_GameDemoTest\TestTextDemo\src\clone\Resume.as"/>
<arg key="pos" value="453"/>
</metadata>
</accessor>
<metadata name="__go_to_ctor_definition_help">
<arg key="file" value="D:\_GameDemoTest\TestTextDemo\src\clone\Resume.as"/>
<arg key="pos" value="269"/>
</metadata>
<metadata name="__go_to_definition_help">
<arg key="file" value="D:\_GameDemoTest\TestTextDemo\src\clone\Resume.as"/>
<arg key="pos" value="32"/>
</metadata>
</type>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
name :timeArea
value : TIMEAREA
name :sex
value : SEX
name :name
value : NAME
name :company
value : COMPANY
name :age
value : AGE