Home > Web Front-end > JS Tutorial > Flash calls methods in js and lets js pass variables to flash. Methods and ideas_javascript skills

Flash calls methods in js and lets js pass variables to flash. Methods and ideas_javascript skills

WBOY
Release: 2016-05-16 17:26:33
Original
939 people have browsed it

JavaScript function in html page:

Copy code The code is as follows:

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:
Copy code The code is as follows:

getURL("javascript: GetSwfUrl()");

ExternalInterface calls JS:
Copy code The code is as follows:

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.*;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template