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.

6
  • 1
    If I test your code, it works fine. What version of FireFox and Flash are you running? Commented Jan 12, 2012 at 12:11
  • Firefox: 9.0.1; Flash: 11.1.102.55 (win7 x64) Commented Jan 12, 2012 at 12:14
  • It also works in chrome. Any other information you can give? Commented Jan 12, 2012 at 12:16
  • console.log(params[0]); giving [ indicates that the parameter is received as a string, doesn't it? Commented Jan 12, 2012 at 12:17
  • possible duplicate of Send array from Flash (AS3) to JavaScript Commented Jan 12, 2012 at 12:17

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

What i had to do is, to replace jsParams from string to array. Then i just passed array ExternalInterface.call("doCall", jsParams);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.