As3.0 and js call each other, js controls the flash color, as3.0js
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 <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 );
}
}
}
// 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:
<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 enables full display of html pages -->
<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>
How to use external js to control flash sound in AS30
My voice is cyclical. Load a sound in 2 seconds. I am under the control of js flashData. DataModel. Sound_open = true ?? How can I change onclick to false when the value is true or not;
How does flash call js functions?
The simplest method for flash to call js is:
GetURL ("javascript: function ()"); // function name of the JS function on the page where FLASH is located.
The simplest way for js to pass variables to flash is:
Flash. setVariable ("variable name", "variable value"); // the id of flash for this FLASH
The situation you are talking about is really not quite clear, ''hope the above can be useful to you''
In fact, JS can directly control FLASH playback. You can find it on the Internet.