views:

945

answers:

2

is there a way to trace an ARRAY in FLASH.

I want to have an output similar to PHPs command:print_r(myArray)

for ex: (in flash):

var event:Array = new Array();
event['name']='david';
trace(event);  // that display anything

while print_r(event) in PHP would display as string:

Array {
['name'] => david,
}

I want to achieve same kind of result in flash.

+2  A: 

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]);
Amarghosh
for(var t:Object inthe only type allowed for loop is string type. , got error message.
David King
Try for(var t in array)
Amarghosh
`for(var t:Object in array)` works in Flex builder 3. Can you post the error message that you're getting?
Amarghosh
`The only type allowed for a for-in loop iterator is String.`
David King
Interesting.. are you using Flex Builder or CS3?
Amarghosh
Flash CS4 , for AS2 application
David King
Okay, that's good to know. I am on Flex Builder 3, AS3. Either `var t:String in array` or `var t:* in array` or just `var t in array` should work for you.
Amarghosh
A: 
function obj_size (o:Object){
    var n=0;
    for (var x in o)
     n++;
    return n;
}

DOES WORK ;)

SO I SOLVED sizeof() evivalend to Array.sizeof();

How ABOUT array.push() for Objects ??

David King