Flash trace,dump,print Array variables

trace(array.join()); would work for numerically indexed arrays. For associative arrays, you have to use for..in construct.

for(var t:Object in array)
  trace(t + " : " + array[t]);

Actionscript trace function (in any actionscript language versions) is pretty much a big shame.

Just try that to laugh:

var a :Array = [1,2,3];
var b :Array = [4,5,6, a];
a[3] = b;

trace(a);

A non shameful trace function should indeed loop over the array's elements and trace the arrays inside the arrays as the AS3 trace function does. But it should also check for circular references between inner and parent arrays inside the root array which is traced. This can be implemented in a recursive or iterative way.

If you're not agree that AS3 trace function is bad then also consider the fact that this function will not let you see if an array is contained inside another. I mean that this code:

var a :Array = [1,2,3];
var b :Array = [a, 4,5,6];

trace(b);

will output this:

1,2,3,4,5,6

although we could expect this kind of output:

[1,2,3],4,5,6

And finally if you have null or undefined values inside your arrays then they'll be traced as empty strings:

var a :Array = [1,2,undefined,3];
var b :Array = [4,5,6, null, a];

trace(b);

will output this:

4,5,6,,1,2,,3

... !!! ...


Try this:

import mx.utils.ObjectUtil;
trace(ObjectUtil.toString(event));

Tags:

Arrays

Flash