"ActionScript" flash interacts with Web pages, ActionScript interacts with JavaScript

Source: Internet
Author: User

Flash is easy to interact with the Web page data, or why Flash will have so much vitality? This is just a cumbersome programming, but also debug flash, and then put on the server debugging. However, this way can receive very good results, flash powerful graphics function, graphic function, can be linked with the parameters of the Web page, with the backend server language, can receive great results.

Here is an example of ActionScript3.0 to illustrate this problem, such as:

IE6 Effect:


Firefox effect:


Once the browser is loaded with flash plugin, Flash will be able to easily communicate with the web. In any browser, now basically the user will be loaded with flash components, so to speak, there is almost no Flash component browser.

First, the flash part

1, first, a new ActionScript3.0 flash, after the new Save as WEBPAGE.FLA, this time the flash does not need such a large size, otherwise the page will have a lot of white, set the size of 500x100px can be. The version of the player is available by default, because the user's browser Flash component is automatically updated. This is not a care.


2. Open the palette through the Widgets, window, or CTRL+F7, and use your own buttons, label text, input box components to arrange the interface.


3, drag out the following interface, set the properties of each component as follows, set its text value, that is, to display the text, set the instance name for the component to be controlled, that is, the ID, such as the button set to Button1, the input box is set to EditField1, For a while, the text value of the label text to be controlled by the Web page is emptied, and its instance name is Label1.


4, then click on the first frame, open the Action panel, or click F9, write the following code:

Import Flash.external.externalinterface;flash.system.security.allowdomain ("*"); Flash.system.Security.allowInsecureDomain ("*");//settings allow all sites to allow Flash to interact with Web pages button1.addeventlistener ("click", function () {//Click Button1 this button Externalinterface.call ("Show", editfield1.text);//Call function show in JavaScript (message {} function, where message this parameter value is filled by EditField1 input}); function JavaScriptShow1 (message1) {///define a functions, and once this function triggers, the values are transmitted. Fill Label1 this label text Label1.text=message1;} Externalinterface.addcallback ("JavaScriptShow1", JavaScriptShow1);//Register JavaScriptShow1 This function, its external name is JavaScriptShow1 , it should generally be the same//web page called the Flash object's JavaScriptShow1 method, which is equivalent to calling the JavaScriptShow1 (message1) {} function in ActionScript

5, the flash part is complete, select File--publish, open the Flash saved folder. In fact, the above content than the "ActionScript" ActionScript3.0 HelloWorld "(Click to open the link) is not much more complicated, but only a couple of words to register ActionScript and JavaScript interaction.



Ii. part of the Web page

1, after, to put this flash layout on the Web page. After Flash is published, it will generate two things in the Web page an HTML and a SWF, the core file is. swf file, HTML file can not be copied, can only draw on the code, otherwise it can not be compatible with wild Fox Zen, Google and other browsers.


This is generated by the Flash webpage.html page, you can learn the code as follows:


2. Flash disables the ability of Flash to call local files. You can only copy this webpage.swf to your server for debugging. Then create a new. HTML page on the server, with swf.html and webpage.swf as examples, if the different examples please set their own absolute path, assuming that the swf.html,swf.html HTML layout is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >< HTML xmlns= "http://www.w3.org/1999/xhtml" lang= "ZH-CN" xml:lang= "ZH-CN" >The subsequent JavaScript layout is the core of ActionScript's interaction with JavaScript, with the following code:
<script type= "Text/javascript" >//the JavaScript function called by ActionScript, which is populated    with the value passed by ActionScript. function Show (message) {            alert (message);    }    Gets the function of the Flash object, different objects have different methods. For compatibility, this is the only way to write.    function Getflash (moviename) {        if (Window.document[moviename]) {            window.document[moviename];        }        if (Navigator.appName.indexOf ("Microsoft Internet") = =-1) {            if (document.embeds && document.embeds[ Moviename])                 return document.embeds[moviename];        }        else {            return document.getElementById (moviename);        }    }    Get the Flash Object    var flash1 = getflash (' webpage ');    JavaScript calls the function    Toflash () {        var Text1 = document.getElementById registered as JavaScriptShow1 in ActionScript ("Text1"). Value;        Flash1. JavaScriptShow1 (Text1);    } </script>

Iii. Summary

In summary, webpage.swf interacts with swf.html such as:


"ActionScript" flash interacts with Web pages, ActionScript interacts with JavaScript

Related Article

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.