As3.0 and js call each other, and js controls the flash color.
Application Scenario: flash is a map. Click on the map to call js. A dialog box is displayed, showing the information you want. js regularly calls the method provided by, then change the flash color.
The following is the as code:
Import flash. events. MouseEvent;
Import flash. text. TextField;
// Add monitoring events to each building
Mc0001.addEventListener (MouseEvent. CLICK, onClick );
Mc0004.addEventListener (MouseEvent. CLICK, onClick );
// Test whether js correctly calls the as and correctly calls 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 response method of the building.
Function onClick (e: MouseEvent): void {
Var mothd: String = "monitorDevices"; // monitorDevices is the method that js provides to the as call.
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 called for js.
// Map Color function mcName building code and colorName color code
Function setName (mcName: String, colorName: String): void
{
If (colorName = null | colorName = "no ")
This [mcName]. gotoAndStop (2 );
Else
This [mcName]. gotoAndStop (colorName );
}
==================================== Below is the js Code ======================
// Call when you click a map building
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 \ storage status'
});
// Return 'Hello from javascript. Hello! ';
}
Function callAs (message ){
// Alert (message );
Var msg = message. split ("@");
// Alert (msg. length );
For (var I = 0; I Var mess = msg [I]. split ("| ");
Var colorName;
Var mcName = '';
// Alert (list. length );
For (var j = 0; 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 );
}
}
}
// The browser is compatible with DOM
Function thisMovie (movieName ){
If (navigator. appName. indexOf ("Microsoft ")! =-1 ){
Return window [movieName];
} Else {
Return document [movieName];
}
}
HTML introduces the swf file:
Id = "monitor" width = "1200px" height = "880px"
Codebase = "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
Name = "monitor" align = "middle"
Play = "true"
Loop = "false"
Quality = "high"
AllowScriptAccess = "sameDomain"
Type = "application/x-shockwave-flash"
Pluginspage = "http://www.adobe.com/go/getflashplayer">