Search code examples
actionscript-3reflectioninstance-variablesmember-variables

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!


Solution

  • 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.