在actioncript中循环对象属性名称 [英] looping through object property names in actionscript
问题描述
我有一个我创建的动态类
public dynamic class SiteZoneFileUploadVO
{
public var destination:String =sitezone;
public var siteZoneId:uint;
public var fileType:String;
public var fileContents:String;
public function SiteZoneFileUploadVO()
{
}
}
当我尝试迭代此对象的属性名称时,它只会迭代动态添加的属性。
parameters.dynVar =value;
(var name:参数中的String)
{
trace(name);
}
即使该对象的所有属性都等于一个值(ive选中此在调试器中)将跟踪的唯一属性名称是dynVar。
如何迭代所有属性名称而不仅仅是动态添加的?
您可以使用 describeType()
使用类的所有方法和变量获取XML,然后过滤出要迭代的属性(例如所有变量),并将它们存储在 XMLList
中。 / p>
作为下一步,您将迭代 XMLList
,并在对象上使用方括号符号来访问过滤的属性由他们的名字。但是,您只能访问公共属性,因为 describeType()
不会查看私有属性。
I have a dynamic class that I have created
public dynamic class SiteZoneFileUploadVO
{
public var destination:String = "sitezone";
public var siteZoneId:uint;
public var fileType:String;
public var fileContents:String;
public function SiteZoneFileUploadVO()
{
}
}
when I try to iterate over this object's property names it only iterates the dynamically added properties.
parameters.dynVar= "value";
for(var name:String in parameters)
{
trace(name);
}
Even though the object has all the properties equal to a value (ive checked this in the debugger) the only property name that will be traced is dynVar.
How can I iterate over all the property names and not just the dynamically added ones?
You can use describeType()
to get an XML with all methods and variables of your class and then filter out the properties you want to iterate over (e.g. all variables) and store them in an XMLList
.
As the next step you would then iterate over the XMLList
and use square bracket notation on your object to access the filtered properties by their names. However, you can only access public properties this way because describeType()
won't look at private properties.
这篇关于在actioncript中循环对象属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!