1

从Flash中的按钮我只想调用一个用jQuery编写的函数。
当我把函数放在jQuery的$(document).ready之外时,它工作正常:
* btw我使用SWFObject来嵌入Flash。Flash AS3 ExternalInterface调用jQuery文档中的函数准备

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> 
+0

这真的不清楚你在问什么。为什么需要在$(document).ready中定义一个函数? – spender 2010-03-02 00:54:07

+0

我需要访问与jQuery创建一个阵列。 \t \t \t \t VAR alt_array = $( “#缩略图IMG”)地图(函数(){ \t \t \t \t \t回$(本).attr(“ALT “); \t \t \t \t}); – FFish 2010-03-02 00:57:44

回答

1

在闪存使得它不定义为jsFunction通话时间。在发生ExternalInterface调用后,您有一个竞争条件$(document).ready正在触发,因此在$(document).ready中定义的任何内容都尚未执行,因此在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(); 
}); 
+0

谢谢你的答案。最后,看到了光..我只是定义var alt_array之外的doc.ready,并可以从Flash访问数组。现在我仍然需要使它与IE7一起工作。 – FFish 2010-03-02 13:00:22