html页面代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <SCRIPT language='JavaScript' charset='utf-8'> function callApp() { var x = document.getElementById("MyFlexApp").myFlexFunction(); //var x = MyFlexApp.myFlexFunction(); alert(x); } </SCRIPT> </head> <body> <button onclick="callApp()">Call App</button> </body> </html>
mxml代码:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> import flash.external.*; public function myFunc():Number { return 42; } public function initApp():void { ExternalInterface.addCallback("myFlexFunction",myFunc); } </mx:Script> </mx:Application>
提示:无法获取属性“myFlexFunction”的值: 对象为 null 或未定义。