I am trying to get the contents of an arraycollection to print out using my debug function (which takes a string). Anyone know how to do this? I would like it would be rather easy but can't seem to find a way...I get the word "Object" printed a lot of the time.
A:
The following method should get you what you need:
public static function arrayCollectionToString( arr:ArrayCollection ):String
{
var toRet:String = "[";
for each( var obj:Object in arr ) {
toRet += obj.toString() + ", ";
}
toRet += "]";
return toRet;
}
If you stick this in the same class as your debug method, you could then use it as follows:
SomeDebugClass.dbgMessage( SomeDebugClass.arrayCollectionToString( myArrayCollection ) );
Dan
2009-08-06 17:40:36
A:
It's a lot cleaner to do:
var str:String = '['+myArrayCol.source.join(', ')+']';
the source property of an ArrayCollection is an Array, so all the usual functions are available.
sharvey
2009-08-11 21:56:07