将数组从 Flash (AS3) 发送到 JavaScript

发布于 2024-07-25 06:57:43 字数 218 浏览 1 评论 0原文

是否可以使用ExternalInterface 调用将数组从Flash (AS3) 发送到JavaScript?

我目前正在 Flash 内的“foreach”循环中多次调用一个函数,但速度太快,JavaScript 无法跟上。

我的想法是创建一个属性数组,将其传递给 JavaScript 函数,然后在 JavaScript 中循环遍历它。

谢谢, 乔什

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱冒险 2024-08-01 06:57:43

是的,这是可能的。

http://livedocs.adobe.com/flash /9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html#call()

...arguments — 要传递的参数
到容器中的函数。 你
可以指定零个或多个参数,
用逗号分隔它们。 他们能
可以是任何 ActionScript 数据类型。 什么时候
调用的是 JavaScript 函数,
ActionScript 类型是
自动转换成
JavaScript 类型; 当电话打到
其他一些 ActiveX 容器,
参数被编码在请求中
消息。

快速测试:

AS 代码:

if(ExternalInterface.available) {
    ExternalInterface.call("jsTest", [0,1,"two",{a:1,b:2}]);
}

JS 代码:

function jsTest(arg) {
    alert(arg);
}

Yes, 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);
}
ˉ厌 2024-08-01 06:57:43

除了使用 JSON 的建议之外,这对于小型数组来说应该更快,并且不需要使用 eval 或外部库来解析。 在 flash 中将数组加入到字符串中,如下所示:

item1|item2|item3|item4

将字符串传递给 JS 并使用 split("|") 再次拆分它

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("|")

人间不值得 2024-08-01 06:57:43

您始终可以创建一个 JSON 对象并将其传递给 JavaScript。

You could always create a JSON object and pass that to JavaScript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文