0

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!

Parris
  • 17,833
  • 17
  • 90
  • 133

2 Answers2

1

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.

Garrt
  • 59
  • 5
  • oh yeaaaa, that would totally get the job done! Although the other part of my program would need to be converted to read json... not such a big deal though. – Parris Apr 16 '10 at 02:31
0

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.

Chris Gutierrez
  • 4,750
  • 19
  • 18