Flex 中的外部接口 API
如何解决mxml程序中的以下错误?
错误是
Loading configuration file /opt/flex/frameworks/flex-config.xml
/home/tom-j/programs/flex/html/aa.mxml(17): Error: Access of undefined property addBody.
ExternalInterface.addCallback("addBody", addBody);
程序是
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Button;
import mx.controls.Alert;
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;
import flash.external.*;
import flash.external.ExternalInterface;
// "javascript function", flash function
ExternalInterface.addCallback("addBody", addBody);
public function addBody():void
{
Alert.show("Got input from JS");
}
]]>
</mx:Script>
</mx:Application>
How to resolve the following error in the mxml program?
The error is
Loading configuration file /opt/flex/frameworks/flex-config.xml
/home/tom-j/programs/flex/html/aa.mxml(17): Error: Access of undefined property addBody.
ExternalInterface.addCallback("addBody", addBody);
Program is
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Button;
import mx.controls.Alert;
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;
import flash.external.*;
import flash.external.ExternalInterface;
// "javascript function", flash function
ExternalInterface.addCallback("addBody", addBody);
public function addBody():void
{
Alert.show("Got input from JS");
}
]]>
</mx:Script>
</mx:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该尝试将此调用放入 onCreationComplete 事件处理程序中:
引发的错误可能是因为在处理
addCallback
行时,不存在addBody
方法。更新从 html 中的 javascript 调用
addBody
方法,您必须嵌入 swf ~如下所示:
要从 javascript 调用
addBody
方法,首先您必须在那里找到 Flash 应用程序:You should try putting this call into an onCreationComplete event handler:
The raised error could be because when processing the
addCallback
line, there did not exist theaddBody
method.Update calling the
addBody
method from javascriptin your html you must have the swf embedded ~like this:
To call the
addBody
method from javascript, first you must locate the flash application there: