Flash and JS Communication method _ Application Skills

Source: Internet
Author: User
Tags setinterval
Today, the main learning JS and Flash is how to communicate drip.

1. Learn First
GetURL (URL, window, variables)

Using the GetURL statement, you can have the specified browser window move to display the specified URL address. Parameter (URL) specifies the URL address of the Web page document to display. Parameter (window) specifies the browser window where you want to display the Web page document, either as a custom window name or

If you want it to perform the call to the JS function, then you can
On (release) {
GetURL (\ "Javascript:alert (' Hello,world ')");

}
If you call a custom function
On (release) {
GetURL (\ "Javascript:aiqi (' Test ')");

}
So the HTML page will define this function, such as
function Aiqi (s) {
alert (s);
}

So you can achieve a simple flash and JS communication

So how to let JS to control flash it.
SetVariable () function
Document.getelemenybyid (\ "Js\"). SetVariable ("myvar\", \ "asdfasdfasdf\");

JS is the ID of the SWF file in HTML

How to use JavaScript to invoke a function rebuke in Flash.
The direct method should be the rice has.
Can simulate. To set a variable in Flash, JavaScript controls the value of the variable, and Flash detects the change
Change the value of the measure, and change the execution function;
Flash
--------------
var stat=0;
SetInterval (test,300) {
if (stat==1) Doflash ();
}
function Doflash () {

}

Javascript
--------------------
Tt. SetVariable ("stat\", 1);

This example, I think has realized the JS and flash interaction.
Explain. It's actually very simple.
First, define a function in the HTML file.
function Aiqi (s) {
Assign a value to a flash
Js. SetVariable ("stat", s);
}
Note JS as the ID of the SWF file
There are two buttons in the SWF file.
On (release) {
GetURL ("Javascript:aiqi (1)");
}
On (release) {
GetURL ("Javascript:aiqi (0)");
}
Through these two buttons, pass the parameter to JS Aiqi () function,
The Aiqi () function dynamically changes the value in stat in Flash.
As in SWF
var stat=0;
var c=0;
SetInterval (function () {
if (stat==1)
Doflash ();
},1000)
function Doflash () {
var1=c++;
}
Call Doflash () when Flash detects a stat value change.
[Action in Frame 1]
function Doflash ()
{
VAR1 = c + +;
}//End of the function
var stat = 0;
var c = 0;
SetInterval (function ()
{
if (stat = 1)
{
Doflash ();
}//End If
}, 1000);
On (release)
{
GetURL ("Javascript:aiqi (1)");
}

On (release)
{
GetURL ("Javascript:aiqi (0)");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.