Program Application scenario: Flash is a map, a click on the map, call JS, pop up a dialog box, display some of the information you want, JS timed call as provided by the method, and then go to change the color of flash.
The following is the as code:
Import flash.events.MouseEvent;
Import Flash.text.TextField;
To increase the number of listening events for each building.
Mc0001.addeventlistener (Mouseevent.click,onclick);
Mc0004.addeventlistener (Mouseevent.click,onclick);
Test whether JS correctly calls as, correctly invokes the input content to flash
function MyTest (): void{
var str:string= "Welcome to ActionScript 3.0=========================================================";
var field:textfield=new TextField ();
FIELD.TEXT=STR;
AddChild (field);
}
Click the Wendy Response method
function OnClick (e:mouseevent): void{
var mothd:string= "Monitordevices";//monitordevices provides the method to the as call for JS
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 is the interface to the JS call
Change map color function mcname Building code, colorname color code
function SetName (mcname:string,colorname:string): void
{
if (Colorname==null | | colorname== "NO")
This[mcname].gotoandstop (2);
Else
This[mcname].gotoandstop (colorname);
}
======================= The following is the JS code =============================
Called when the mouse clicks the map Wendy
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 status '
});
Addwin = $.ligerdialog.open ({
URL: ' <%=contextpath%>/showposdetailaction!getserverstatus.action?floorcode= ' +floorcode,
height:600,
width:600,
TOP:50,
left:700,
Titlemessage: ' Server \ Lap State '
});
Return ' Hello from JavaScript. How are you doing! ‘;
}
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);
}
}
}
Browser-compatible access to the DOM
function Thismovie (moviename) {
if (Navigator.appName.indexOf ("Microsoft")! =-1) {
return Window[moviename];
}else {
return Document[moviename];
}
}
HTML introduces SWF file:
<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 to make HTML pages fully visible-
<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>
as3.0 and JS call each other, JS control the color of flash