程序应用场景:flash是一副地图,地图上一单击,就调用js,弹出一个对话框,显示一些自己想要的信息;js定时调用as提供的方法,然后去改变flash的颜色。
以下是as代码:
import flash.events.MouseEvent;
import flash.text.TextField;
//给每一栋楼增加监听事件
mc0001.addEventListener(MouseEvent.CLICK,onClick);
mc0004.addEventListener(MouseEvent.CLICK,onClick);
//测试js是否正确调用as,正确调用输入内容到flash上
function myTest():void{
var str:String="Welcome to ActionScript 3.0=========================================================";
var field:TextField=new TextField();
field.text=str;
addChild(field);
}
//单击楼栋响应方法
function onClick(e:MouseEvent):void{
var mothd:String="monitorDevices";//monitorDevices为js提供给as调用的方法
var floorcode:String=null;
if(e.currentTarget==mc0001){
floorcode="0001";
}else if(e.currentTarget==mc0004){
floorcode="0003";
}
ExternalInterface.call(mothd,floorcode);
}
//ExternalInterface.addCallback("toJs",myTest);
ExternalInterface.addCallback("setColor",setName);//setColor为给js调用的接口
//改变地图颜色函数mcName楼栋代码,colorName颜色代码
function setName(mcName:String,colorName:String):void
{
if(colorName==null || colorName=="no")
this[mcName].gotoAndStop(2);
else
this[mcName].gotoAndStop(colorName);
}
=======================以下是js代码=============================
//鼠标单击了地图楼栋时调用
function monitorDevices(floorcode){
//alert(floorcode);
addWin = $.ligerDialog.open({
url: ‘<%=contextPath%>/showPosDetailAction!showPosInfo.action?floorcode=‘+floorcode,
height: 700,
width: 600,
top:50,
left:50,
titleMessage:‘POS状态‘
});
addWin = $.ligerDialog.open({
url: ‘<%=contextPath%>/showPosDetailAction!getServerStatus.action?floorcode=‘+floorcode,
height: 600,
width: 600,
top:50,
left:700,
titleMessage:‘服务器\圈存状态‘
});
//return ‘Hello from javascript。 你好!‘;
}
function callAs(message) {
//alert(message);
var msg=message.split("@");
//alert(msg.length);
for(var i=0;i<msg.length;i++){
var mess=msg[i].split("|");
var colorName;
var mcName=‘‘;
//alert(list.length);
for(var j=0;j<list.length;j++){
//alert(list[j].floorcode);
if(mess[0]==list[j].floorcode){
mcName=list[j].mapcode;
}
}
//alert(mcName+"===");
if(mess[1]=="0"){
colorName="red";
}else if(mess[1]=="1"){
colorName="normal";
}
//alert(msg[i]+‘ mcName:‘+mcName+‘ colorName:‘+colorName);
if(mcName!=‘‘){
thisMovie("monitor").setColor(mcName,colorName);
}
}
}
//浏览器兼容访问DOM
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
}else {
return document[movieName];
}
}
HTML引入swf文件:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="monitor" width="1200px" height="880px"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="<%=contextPath%>/flash/CauMap.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="wmode" value="opaque"/><!-- transparent能使html页面完全显示 -->
<embed wmode="Opaque" src="<%=contextPath%>/flash/CauMap.swf" quality="high" bgcolor="#869ca7"
name="monitor" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>