thomas
thomas

Reputation: 2642

flex get contents of arraycollection as string

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.

Upvotes: 2

Views: 11614

Answers (4)

Kamran Aslam
Kamran Aslam

Reputation: 123

You can use

ObjectUtil.toString(arrayCollection);

Upvotes: 0

Lucas Matos
Lucas Matos

Reputation: 2908

Default is allready coma separated

array.toString()

Upvotes: 0

sharvey
sharvey

Reputation: 8145

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.

Upvotes: 10

Dan
Dan

Reputation: 836

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 ) );

Upvotes: 0

Related Questions