我想按声明顺序将对象的所有变量放入ByteArray。 对象可以是扩展对象。 这是我的代码:
private static function getVariables( packet:*): Array
{
var vars:Array = new Array();
var description:XML = describeType(packet);
Alert.show(description);
var descriptionList:XMLList =
description..accessor.(@access != "writeonly") + description..variable;
for each ( var info:XML in descriptionList )
{
vars.push( { name: info.@name, type: info.@type,
pos: uint(info..metadata..arg.@value) } );
}
vars.sortOn( "pos", Array.DESCENDING );
return vars;
}
public static function print():void
{
var o:C = new C();
var description:XML = describeType(o);
Alert.show(description);
}
public class A
{
public var a_of_A:int;
public var b_of_A:int;
}
public class B extends A
{
public var i_of_B:int;
public var j_of_B:int;
}
public class C extends B
{
public var d_of_C:int;
public var e_of_C:int;
}
<type name="packet::C" base="packet::B" isDynamic="false" isFinal="false" isStatic="false">
<extendsClass type="packet::B"/>
<extendsClass type="packet::A"/>
<extendsClass type="Object"/>
<variable name="j_of_B" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="110"/>
</metadata>
</variable>
<variable name="i_of_B" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="84"/>
</metadata>
</variable>
<variable name="e_of_C" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="110"/>
</metadata>
</variable>
<variable name="b_of_A" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="81"/>
</metadata>
</variable>
<variable name="d_of_C" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="84"/>
</metadata>
</variable>
<variable name="a_of_A" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="55"/>
</metadata>
</variable>
<metadata name="__go_to_definition_help">
<arg key="pos" value="54"/>
</metadata>
</type>
private static function getVariables( packet:*): Array
{
var vars:Array = new Array();
var description:XML = describeType(packet);
Alert.show(description);
var descriptionList:XMLList =
description..accessor.(@access != "writeonly") + description..variable;
for each ( var info:XML in descriptionList )
{
vars.push( { name: info.@name, type: info.@type,
pos: uint(info..metadata..arg.@value) } );
}
vars.sortOn( "pos", Array.DESCENDING );
return vars;
}
public static function print():void
{
var o:C = new C();
var description:XML = describeType(o);
Alert.show(description);
}
public class A
{
public var a_of_A:int;
public var b_of_A:int;
}
public class B extends A
{
public var i_of_B:int;
public var j_of_B:int;
}
public class C extends B
{
public var d_of_C:int;
public var e_of_C:int;
}
<type name="packet::C" base="packet::B" isDynamic="false" isFinal="false" isStatic="false">
<extendsClass type="packet::B"/>
<extendsClass type="packet::A"/>
<extendsClass type="Object"/>
<variable name="j_of_B" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="110"/>
</metadata>
</variable>
<variable name="i_of_B" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="84"/>
</metadata>
</variable>
<variable name="e_of_C" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="110"/>
</metadata>
</variable>
<variable name="b_of_A" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="81"/>
</metadata>
</variable>
<variable name="d_of_C" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="84"/>
</metadata>
</variable>
<variable name="a_of_A" type="int">
<metadata name="__go_to_definition_help">
<arg key="pos" value="55"/>
</metadata>
</variable>
<metadata name="__go_to_definition_help">
<arg key="pos" value="54"/>
</metadata>
</type>
“pos”是什么?
我尝试打印xml,但我找不到“pos”的意思....
答案 0 :(得分:0)
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#sortOn()
AS3 function sortOn(fieldName:Object, options:Object = null):Array
所以“pos”是字段名称。