从 javascript 调用 actionscript 3 函数,addCallback 不起作用
calling actionscript 3 function from javascript with addCallback not working
我有一个项目需要从 javascript 调用 actionscript 3 函数。我从 Whosebug 和 adobe 阅读了许多答案,并创建了一个简单的测试应用程序。在那里,我使用 ExternalInterface.addCallback 注册了这两个函数,并且还在 actionscript 和 html.
中包含了安全权限
动作脚本 3 嵌入代码
我没有使用外部 .as 文件,而是使用操作面板创建代码。
import fl.controls.Button
import flash.events.MouseEvent;
flash.system.Security.allowDomain("*")
var butt:Button = new Button();
addChild(butt);
butt.label = "hello";
butt.toggle = true;
butt.move(50, 50);
butt.height = 100;
butt.addEventListener(MouseEvent.CLICK, clickhandle);
function clickhandle(e:MouseEvent)
{
if(butt.height == 100)
butt.height = 200;
else butt.height = 100;
}
ExternalInterface.addCallback("callas", clickhandle);
测试应用程序将显示一个 ac3 按钮。单击该按钮后,它将通过单击处理程序 'clickhandle' 切换其高度的展开和折叠。这是我打算从 javascript.
调用的函数
HTML代码
<html>
<head>
<script>
function callas() {
var hehe = document.getElementById('cvpanel');
console.log(hehe);
hehe.clickhandle();
}
</script>
</head>
<body>
<p>Test</p>
<object id='cvpanel' name='cvpanel' width="425" height="350" type="application/x-shockwave-flash" data="one.swf">
<param value="one.swf" name="movie">
<param name="allowscriptaccess" value="always"/>
<p>You need Flash to see it.</p>
</object>
</body>
</html>
应用程序 运行 在 http://localhost 下通过 apache 和所有需要的文件都在同一个文件夹中。我可以 运行 应用程序并且可以看到出现的按钮。通过单击它,它们会按预期切换高度。
当我从浏览器控制台调用函数 callas 时,我在控制台中收到错误
"TypeError: hehe.clickhandle is not a function"
在 Firefox 和类似的 Internet Explorer 中。
有什么遗漏吗?
在 Flash 中,您将 clickhandle 公开为 callas
ExternalInterface.addCallback("callas", clickhandle);
所以你应该从 javascript
调用 callas()
var hehe = document.getElementById('cvpanel');
hehe.callas();
我有一个项目需要从 javascript 调用 actionscript 3 函数。我从 Whosebug 和 adobe 阅读了许多答案,并创建了一个简单的测试应用程序。在那里,我使用 ExternalInterface.addCallback 注册了这两个函数,并且还在 actionscript 和 html.
中包含了安全权限动作脚本 3 嵌入代码
我没有使用外部 .as 文件,而是使用操作面板创建代码。
import fl.controls.Button
import flash.events.MouseEvent;
flash.system.Security.allowDomain("*")
var butt:Button = new Button();
addChild(butt);
butt.label = "hello";
butt.toggle = true;
butt.move(50, 50);
butt.height = 100;
butt.addEventListener(MouseEvent.CLICK, clickhandle);
function clickhandle(e:MouseEvent)
{
if(butt.height == 100)
butt.height = 200;
else butt.height = 100;
}
ExternalInterface.addCallback("callas", clickhandle);
测试应用程序将显示一个 ac3 按钮。单击该按钮后,它将通过单击处理程序 'clickhandle' 切换其高度的展开和折叠。这是我打算从 javascript.
调用的函数HTML代码
<html>
<head>
<script>
function callas() {
var hehe = document.getElementById('cvpanel');
console.log(hehe);
hehe.clickhandle();
}
</script>
</head>
<body>
<p>Test</p>
<object id='cvpanel' name='cvpanel' width="425" height="350" type="application/x-shockwave-flash" data="one.swf">
<param value="one.swf" name="movie">
<param name="allowscriptaccess" value="always"/>
<p>You need Flash to see it.</p>
</object>
</body>
</html>
应用程序 运行 在 http://localhost 下通过 apache 和所有需要的文件都在同一个文件夹中。我可以 运行 应用程序并且可以看到出现的按钮。通过单击它,它们会按预期切换高度。
当我从浏览器控制台调用函数 callas 时,我在控制台中收到错误
"TypeError: hehe.clickhandle is not a function"
在 Firefox 和类似的 Internet Explorer 中。
有什么遗漏吗?
在 Flash 中,您将 clickhandle 公开为 callas
ExternalInterface.addCallback("callas", clickhandle);
所以你应该从 javascript
调用 callas()var hehe = document.getElementById('cvpanel');
hehe.callas();