2

I have flash application, which creates array and calls javascript function.

var jsParams = ["3011","3012","3013","3014","3015"];
ExternalInterface.call("doCall", jsParams);

And this is my javascript function:

function doCall(params) {
  console.log(params);
  console.log(params[0]);
}

The output in the firebug is:

["3011","3012","3013","3014","3015"]
[

But for the second line i was expecting 3011 and not [. Then i have tried to call same function with same params from firebug and the function outputed:

doCall(["3011","3012","3013","3014","3015"]);
["3011","3012","3013","3014","3015"]
3011

My question is how to pass params from actionscript to javascript as array and not as string value.

Thanks.

JercSi
  • 1,037
  • 1
  • 9
  • 19
  • 1
    If I test your code, it works fine. What version of FireFox and Flash are you running? – Rick van Mook Jan 12 '12 at 12:11
  • Firefox: 9.0.1; Flash: 11.1.102.55 (win7 x64) – JercSi Jan 12 '12 at 12:14
  • It also works in chrome. Any other information you can give? – Gran Jan 12 '12 at 12:16
  • `console.log(params[0]);` giving `[` indicates that the parameter is received as a string, doesn't it? – Yoshi Jan 12 '12 at 12:17
  • possible duplicate of [Send array from Flash (AS3) to JavaScript](http://stackoverflow.com/questions/1058589/send-array-from-flash-as3-to-javascript) – taskinoor Jan 12 '12 at 12:17
  • @taskinoor many thanks! I couldn't find any question like mine, so i've posted it. But it looks like, that someone was already asking about this. – JercSi Jan 12 '12 at 12:21

2 Answers2

1

It looks like the params variable is being passed in as a string, rather than an array.

Square bracket notation, when applied to a string, represents the character at the supplied index, which in this case would be the '[' (position 0).

You should look into JSON decoding to find a safe way to convert the string back into an array , I wouldn't recommend eval, and JSON.decode isn't widely supported.

beeglebug
  • 3,522
  • 1
  • 23
  • 39
0

have you tried encapsulating the array within another array?

ExternalInterface.call("doCall", [jsParams]);

I think a initial array is so you can pass mulitple sets of parameters

  • What i had to do is, to replace jsParams from string to array. Then i just passed array ExternalInterface.call("doCall", jsParams); – JercSi Jan 13 '12 at 06:17