JavaScript function in html page:
function GetSwfUrl()
{
var pics1 = parseInt(Math.random()*5) 1;
var pics2 = parseInt(Math.random()*5) 1;
document.my_swfId.SetVariable("pic01Num ", pics1);
document.my_swfId.SetVariable("pic02Num", pics2);
}
Explanation: pic01Num and pic02Num are variables defined in Flash, the above function will JS The variables pics1 and pics1 are assigned to the Flash variables pic01Num and pic02Num respectively. my_swfId is the id of swf in the html page.
****************
Communication with JS in Flash can use the traditional getURL. After Flash8, you can use ExternalInterface. ExternalInterface is functionally similar to the fscommand(), CallFrame(), and CallLabel() methods, but is more flexible and general-purpose. It is recommended to use ExternalInterface for communication between JavaScript and ActionScript.
getURL calls JS:
getURL("javascript: GetSwfUrl()");
ExternalInterface calls JS:
import flash.external.ExternalInterface;//Import the ExternalInterface class
ExternalInterface.call("GetSwfUrl()");
Note: If you want to use ExternalInterface, currently The frame must have import flash.external.ExternalInterface; or import flash.external.*;