1.在ActionScript 中调用JavaScript
Js 如下:
1<script language="javaScript">
2 function printBookInfo(title,price){
3 alert("Book Title:"+title+ " is price at:"+price;
4 }
5
6
7</script>
As如下:
1if(ExternalInterface.available){
2 var title:String = "Actionscript";
3 var price:uint = 300;
4 var result:String = ExternalInterface.call("printBookInfo",title,price);
5 Alert.show(result);
6
7}else{
8
9 Alert.show("External interface is not vaailable")
10}
2,JavaScript 调用 ActionScript
ActionScript中注册调用方法
ExternalInterface.addCallback("myFunction",sayHello);
private sayHello(name:String):String{
return "Helloo from AS,"+name;
}
JS:
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName]
}else{
return document[movieName]
}
}
function callExternal() {
thisMovie("swfId").showAlert()
}
<script type="text/javascript">
var f4=new SWFObject('test.swf', "swfId", "400", "300", "8", "#000",true);
//new SWFObject(swf, id, width, height, version, background-color [, quality, xiRedirectUrl, redirectUrl, detectKey]);
f4.addParam('allowScriptAccess','sameDomain');
f4.addParam('wmode','transparent');
f4.skipDetect="false";
f4.addParam('bgcolor','#c5d1f0');
f4.write("flvPlayerDivId");
</script>