Flash is easy to interact with the Web page data, or why Flash will have so much vitality? The only way to do this is to be more troublesome, to debug flash, and then to debug on the server again.
Just this way you can get very good results. Flash powerful drawing function, graphics function, can be linked with the Web page of the reference, with the backend server language, you can receive very large results.
The following example uses ActionScript3.0 to illustrate this problem, for example:
IE6 Effect:
Firefox effect:
Once the browser is loaded with flash plugin, Flash can easily communicate with the Web page.
No matter what browser it is, the user is now basically loaded with flash components, so to speak. There is almost no browser that does not have a Flash component installed.
First, the flash part
1, first, create a new ActionScript3.0 flash. After the new is saved 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 number of the player is available by default, as the user's browser Flash component will be actively updated by itself.
This is not a care.
2. Open the palette by using the form-by component, or CTRL+F7, and use the button, label text, input box component to place the interface.
3. Drag out the interface, for example, to set the properties of each component, such as the following, to set its text value. That is, the text to be displayed, set the instance name for the component you want to control, that is, the ID, for example, the button is set to Button1. The input box is set to EditField1. For a while, the text value of the label text controlled by the Web page is emptied, in fact the example name is Label1.
4, then click on the first frame, open the Action panel, or click F9. Write code such as the following:
Import Flash.external.externalinterface;flash.system.security.allowdomain ("*"); Flash.system.Security.allowInsecureDomain ("*");//settings agree that all sites agree to the interaction between Flash and Web page button1.addeventlistener ("click", function () {//click Button1 this Buttonexternalinterface.call ("show", editfield1.text);//Call function show in JavaScript ( message) {} function, in which the value of message is filled by EditField1 input}), function JavaScriptShow1 (message1) {///define a functions, and once this function is triggered, the transmitted values are Fill Label1 this label text Label1.text=message1;} Externalinterface.addcallback ("JavaScriptShow1", JavaScriptShow1);//register JavaScriptShow1 this function. Its external name is JAVASCRIPTSHOW1. Generally should be the same//Web page Call Flash Object JavaScriptShow1 method. is equivalent to calling the JavaScriptShow1 (message1) {} function in ActionScript
5. The part of Flash is complete at this time. Select File---Publish to open the saved directory for Flash.
In fact, the above content is not much more complicated than the "ActionScript" ActionScript3.0 HelloWorld (click to open link), just a couple of sentences to register ActionScript's interaction with JavaScript.
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 with a SWF, the core file is. swf file, HTML file can not be copied, only to learn from the code, otherwise not compatible with wild Fox Zen, Google and other browsers.
This is generated by Flash webpage.html page. The following code can be used for reference:
2. Because 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, and here are examples of the same folder as Swf.html and webpage.swf, if not the same example please set the absolute path yourself. If the HTML layout for swf.html,swf.html is the following:
<! 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" >After the JavaScript layout. Is the core of ActionScript's interaction with JavaScript. The code is as follows:
<script type= "Text/javascript" >//a JavaScript function that is called to ActionScript. Message This parameter is filled with the function show (message) { alert (message) as the value passed by ActionScript; } Gets the function of the Flash object. Different objects have different methods. For compatibility. Just write that. 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 JavaScriptShow1 function Toflash () { var Text1 = document.getElementById in ActionScript ("Text1"). Value; Flash1. JavaScriptShow1 (Text1); } </script>
Iii. Summary
In summary, webpage.swf interacts with swf.html for example by:
"ActionScript" flash interacts with Web pages, ActionScript interacts with JavaScript