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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" language="javascript" src="swfobject.js"></script>
<script language="javascript">
//调用flash中的方法,"swfId"为html页中swf的id
function callExternal() {
thisMovie("swfId").showAlert()
}
//搭建js与flash互通的环境
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName]
}else{
return document[movieName]
}
}
</script>
</head>
<body>
<input type="button" onClick="callExternal()" value="调用flash中的方法">
<div id="flvPlayerDivId" style="border:1px solid #eee; width:400px; height:300px;"> </div>
<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>
</body>
</html>
AS:
//舞台上需要一个名为"txt"的动态文本
import flash.external.ExternalInterface;
function showAlert() {
//ExternalInterface.call("jsAlert("+i+")");//flash调用js中的函数
txt.text = "js调用了flash函数";
}
//允许js中的flAlert()调用flash中的showAlert()
ExternalInterface.addCallback("showAlert", null, showAlert);//允许js调用flash中的函数