如何调用从JavaScript闪存动作回调方法?闪存、回调、动作、方法

2023-09-08 12:06:38 作者:帝皇°

我试着打从JavaScript闪存回调方法。 但似乎不工作。 闪光动作脚本例如code是如下图所示[简体]:

I tried to call a flash callback method from JavaScript. But it seems not working. The flash action script example code is like below [Simplified]:

import flash.events.ActivityEvent; 
import flash.events.StatusEvent; 
import flash.external.ExternalInterface;

var test_var = ExternalInterface.addCallback("js_method_to_call", flash_method);


function flash_method()
{   
  return "test"; 
}

JavaScript示例code被写入低于[简体]:

The javascript example code is written below [Simplified]:

 function callFlashMethod(){
   var flashFile = eval("window.document.test");
   flashFile.js_method_to_call;
 }
 function loadTest(){
   swfobject.embedSWF("test.swf", "test", "1", "1", "10.0.0", false);
 }

 $(document).ready(function(){
   loadTest();
   callFlashMethod();
 });

它总是显示在火错误控制台中的错误flashFile.js_method_to_call不是一个函数。

It is always display the error in fire bug console "flashFile.js_method_to_call is not a function".

推荐答案

下面的东西,应该确实不错:

Here's something that should work really good:

使用SWFObject.js嵌入Flash内容:

Use SWFObject.js for embedding the Flash content:

// Embedding through SWFObject rocks in comparison with Adobe shits:
var flashvars = {};

var params                  =   {};
params.menu                 =   "false";
params.salign               =   "t";
params.scale                =   "noscale";
params.wmode                =   "transparent";
params.allowScriptAccess    =   "always";

var attributes              =   {};
attributes.id = "${swf}";

swfobject.embedSWF("${swf}.swf", "flashDiv", "${width}", "${height}", "9.0.0", "", flashvars, params, attributes);

从未有人把 分时图 讲得这么透彻,集万本炒股书之精华 分享

使用此为HTML:

Use this for the HTML:

<body>
    <div id="flashDiv"></div>
</body>

要调用您的Flash方法,使用这种模式:

To call your Flash method use this pattern:

// Functions needed for calling Flex ExternalInterface
function thisMovie(movieName) 
{
    if (navigator.appName.indexOf("Microsoft") != -1) 
    {
        return window[movieName];
    } 
    else 
    {
        return document[movieName];
    }
}

调用Flash方法:

Call the Flash method:

function callFlashMethod()
{
    thisMovie("${swf}").js_method_to_call();
}