flex和javascript互相调用的一个例子
flex 方面 :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="initApp()"
themeColor="#29AE58">
<mx:Button x="42"
y="43"
label="按钮"
click="btn1_click()"
enabled="true"
labelPlacement="left">
</mx:Button>
<mx:Label id="Label1"
x="132"
y="45"
text="Label"/>
<mx:Script>
<![CDATA[
import flash.external.*;
import mx.controls.Alert;
private function btn1_click():void
{
Label1.text="哈哈 今年是2012";
}
public function dyjs():void
{
var f:String="js";
var m:String=ExternalInterface.call(f);
}
public function wsflex():Number
{
Alert.show("呵呵 我是flex");
return 42;
}
public function initApp():void
{
ExternalInterface.addCallback("dyflex", wsflex);
}
]]>
</mx:Script>
<mx:RadioButtonGroup id="radiogroup1"/>
<mx:Button x="194"
click="dyjs()"
y="43"
label="调用js"/>
</mx:Application>
html 方面
<html>
<head>
<script type="text/javascript">
function js()
{
alert('我是js');
}
function dyflex()
{
var a = document.getElementById("myname");
var x = a.dyflex();
//alert(x);
}
</script>
</head>
<body>
<input id="Button1" type="button" value="button" onclick="dyflex();" />
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="myname" width="100%"
height="100%" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="test.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="test.swf" quality="high" bgcolor="#869ca7" width="100%" height="100%"
name="sample19_5" align="middle" play="true" loop="false" quality="high" allowscriptaccess="sameDomain"
type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</body>
</html>