如何从 javascript 调用 flash actionscript 回调方法?
我尝试从 JavaScript 调用 Flash 回调方法.但它似乎不起作用.Flash动作脚本示例代码如下[简化]:
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示例代码写在[简化]下面:
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();
});
fire bug 控制台总是显示错误flashFile.js_method_to_call is not a function".
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();
}