开发者

Is it possible to get all member variables in flash(AS3)?

I am trying grab all the member variables in AS3, and then foreach one i would like to process it in various 开发者_运维问答ways. I would need the name and then if it is a collection of some type I would like to loop through that collection as well. I am attempting to essentially serialize in a somewhat custom fashion. Thanks!


If you're looking to serialize an object, you will definitely want to use JSON.

JSON basically converts objects into strings and also the other way round using an encode()/serialize() and decode()/deserialize() function.

There is a built-in JSON class in AS3, and it's really easy to use.

Once you do something like:

var myObject:Object = {};
var myObjectString:String = JSON.serialize(myObject);

After getting the string, you can do all your switch logic to manipulate each of your different variables and convert it back into an object via the deserialize() function.


You could use describeType. That returns information about the object as XML. By default, you can iterate over public properties in objects. You could try something like...

// the object to iterate over
var someObj:Object = {};

for(var prop:String in someObj) {
    // check to see if its something you want to iterate over
    if (someObj[prop] is Array) {
        // iterator over the property here
    }
}

I hope this answers your question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜