簡體   English   中英

Flash AS3 ExternalInterface調用可在jQuery文檔中准備好功能

[英]Flash AS3 ExternalInterface call to function inside jQuery document ready

從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>

在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();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM