flex get contents of arraycollection as string
11,483
Solution 1
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 ) );
Solution 2
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.
Author by
thomas
Updated on June 24, 2022Comments
-
thomas about 2 years
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.
-
Matt Chan over 11 yearsThis is if you're accessing the 'source' property (which is an Array) on the ArrayCollection object.
-
Edyn almost 11 yearsThis will have a trailing comma at the end of the list. Use the answer below from sharvey.