【问题标题】:Flash AS3 ExternalInterface call to function inside jQuery document readyFlash AS3 ExternalInterface 调用函数在 jQuery 文档中准备就绪
【发布时间】:2010-03-02 00:39:04
【问题描述】:

从 Flash 中的一个按钮,我只想调用一个用 jQuery 编写的函数。
当我将函数放在 jQuery 的 $(document).ready 之外时,它可以正常工作:
*顺便说一句,我使用 SWFObject 嵌入 Flash。

AS3:

import flash.external.ExternalInterface;
function test_fnc(event:Event):void {
    ExternalInterface.call("jsFunction", "hello world");
}
test_mc.addEventListener("click", test_fnc);

JS:

<script type="text/javascript">     
    function jsFunction(words) {
        alert(words); // "hello world";
    }
    $(document).ready(function() {
        // not from here
    });
</script>

【问题讨论】:

  • 真的不清楚你在问什么。为什么需要在 $(document).ready 中定义一个函数?
  • 我需要访问一个用 jQuery 创建的数组: var alt_array = $("#thumbnails img").map(function() { return $(this).attr("alt"); } );

标签: jquery flash actionscript-3 externalinterface document-ready


【解决方案1】:

在 Flash 调用 jsFunction 时,它没有被定义。在调用 ExternalInterface 后,$(document).ready 会触发竞争条件,因此在 $(document).ready 中定义的任何内容都不会执行,因此在 Flash 进行调用时不可用。

回应您的评论:

您需要准备好 Flash 和准备好文档才能使其正常工作。我不确定初始化顺序是否得到保证,所以我建议您从 Flash 调用一个已知函数,告诉 JS 它已准备好。也许是这样的:

var waitingForItems=2;
function itemReady()
{
    //called from both Flash and $(document).ready
    --waitingForItems;
    if(waitingForItems==0)
    {
        //create your array
        //send to Flash by calling Flash rather having Flash call JS
    }
}
$(document).ready(function(){
    itemReady();
});

【讨论】:

  • 感谢您的回答。最后看到了曙光。我刚刚在 doc.ready 之外定义了 var alt_array 并且可以从 Flash 访问该数组。现在我仍然需要让它与 IE7 一起工作。
猜你喜欢
  • 2011-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-15
  • 1970-01-01
  • 2017-09-09
  • 1970-01-01
相关资源
最近更新 更多