开发者

How to access to Object property When the propety I want to access to it's in a String variable

It's too complicate to explain but I'll give you an example

I have an AS3 ResultEvent Object and this object has several propeties which can be accessed by this like: event.result.name or event.result.age .....

and, I have this String variable: eventProperty:String that contains "name" or "age" How do I access to event.re开发者_如何学JAVAsult. with the variable?

thank you.


The ActionScript (or ECMAScript) . operator is just syntactic sugar, useful but not really needed. For what you want to do you can use the normal object property access operator [].

So you have to do it like this event.result[ eventProperty ].

Good luck, Alin


You should probably move your ResultEvent object into an actual Object type first. Then you can access the properties via the object. If your object is an arraycollection, make sure to immediately pass the ResultEvent into an arraycollection since you cannot cast it as you normally might (ArrayCollection)ResultEvent. Here is how to throw the result into an object:

var yourObjectName:Object = event.result;

and here is how to throw it into an arraycollection if you need to:

var yourArrayCollection:ArrayCollection = event.result as ArrayCollection;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜