admin管理员组文章数量:1206930
Is it possible to send an array from Flash (AS3) to JavaScript using an ExternalInterface call?
I currently am calling a function multiple times from a 'for each' loop inside Flash but it goes too fast for the JavaScript to keep up.
My idea is to create an array of the attributes, pass that to the JavaScript function and then to loop through that in the JavaScript.
Thanks, Josh
Is it possible to send an array from Flash (AS3) to JavaScript using an ExternalInterface call?
I currently am calling a function multiple times from a 'for each' loop inside Flash but it goes too fast for the JavaScript to keep up.
My idea is to create an array of the attributes, pass that to the JavaScript function and then to loop through that in the JavaScript.
Thanks, Josh
Share Improve this question asked Jun 29, 2009 at 14:20 JoshJosh 6,3222 gold badges38 silver badges56 bronze badges 1- 1 Just found this which maybe causing my issues scottgmorgan.com/blog/index.php/tag/externalinterface Still interested in the array though if possible. – Josh Commented Jun 29, 2009 at 14:24
3 Answers
Reset to default 8Yes, it's possible.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html#call()
... arguments — The arguments to pass to the function in the container. You can specify zero or more parameters, separating them with commas. They can be of any ActionScript data type. When the call is to a JavaScript function, the ActionScript types are automatically converted into JavaScript types; when the call is to some other ActiveX container, the parameters are encoded in the request message.
A quick test:
AS code:
if(ExternalInterface.available) {
ExternalInterface.call("jsTest", [0,1,"two",{a:1,b:2}]);
}
JS code:
function jsTest(arg) {
alert(arg);
}
Further to the suggestion of using JSON, this should be faster for small arrays and wouldn't require the use of eval or an external library to parse. Join an array in a string like this in flash:
item1|item2|item3|item4
Pass the string to the JS and split it again using split("|")
You could always create a JSON object and pass that to JavaScript.
本文标签: Send array from Flash (AS3) to JavaScriptStack Overflow
版权声明:本文标题:Send array from Flash (AS3) to JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738720376a2108707.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论