生成flash的mxml文件源码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <fx:Script> <![CDATA[ private function hello_world():void{ ExternalInterface.call("js_hello_world"); } ]]> </fx:Script> <s:Button id="btn" label="Button" click="hello_world()"/> </s:Application>
插入flash的html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>使用ExternalInterface调用JS方法-无参数、无返回值!</title> <script type="text/javascript" src="swfobject.js"></script> <script type="text/javascript"> function js_hello_world(){ alert("使用ExternalInterface调用JS方法-无参数、无返回值!"); } </script> </head><body>
<div id="flash"></div> <script type="text/javascript"> swfobject.embedSWF("js.swf", "flash", "400", "325", "11.1.0", "playerProductInstall.swf", {}); </script><embed src="js.swf" quality="high" pluginspage="" type="application/x-shockwave-flash" width="400" height="325"></embed>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="" width="400" height="325">
<param name="movie" value="js.swf" /> <param name="quality" value="high" /> </object> </body> </html>注:object方式无法调用JS方法
参考: