Example of communication between JavaScript and Macromedia Flash

Source: Internet
Author: User
Tags html input text dreamweaver
Example of communication between JavaScript and Macromedia Flash
Original article address: www.macromedia.com/support/flash/ts/documents/java_script_comm.htm
Note: Some minor operations are slightly modified. There are many similar articles, but this is very authoritative.

Below are some examples of direct communication between Flash and HTML files using Javascript. Each example has a simple step.

This article discusses three basic Flash/Javascript communication methods:
Javascript-to-Flash Communication-use the javascript method of Flash Player
Communication between Flash and Javascript-use Flash fscommand
Flash-to-Flash Communication ---------- use a local connection object or a combination of the two technologies

Not all browsers attach great importance to scripts. To communicate with Flash players, the browser must have built-in hooks so that flash players can 'snoop '. The browser must be of the following types:
Netscape Navigator 3.0-4.7x, and Netscape 6.2 or higher
(Windows 95/98/NT/2000/XP or MacOS; Java and LiveConnect are allowed)
Internet Explorer 3.0 or higher
(Windows 95/98/NT/2000/XP only; ActiveX allowed)

Note: Internet Explorer on Macintosh and Netscape6 of earlier versions do not support this method. Please refer to the additional information in this article.

Communication between Javascript and Flash

This example demonstrates how to use the Flash method to send the variable from the HTML input text to the Flash file on the page. The HTML input data is transmitted to the Flash file through the Flash SetVariable method.

Example:
Download the source file: javascript_to_flash.zip (17 k)

Steps:

Flash in progress
1. Create a new file and save it as javascript_to_flash.fla
2. Use a text tool to create a text field on the stage
3. Select this Text field. On the property panel, select Dynamic Text from the drop-down list and fill in "myVar" in the variable column"
Note: The best practice is to use Instance and use myVar. text to change the value of myVar. For simplicity and compatibility with Flash4 and Flash5, we use the form of variable names.
4. Save the file
5. Publish HTML and SWF files

Dreamweaver
The next step is to move to Dreamweaver. Of course, it can also be another HTML editor.
1. Open the HTML file released in the previous step.
2. Insert the generated SWF file and OBJECT/EMBED tag
(1) Insert> Media> Flash and select the Flash
(2) to switch to the Code view, we need to modify the selected <OBJECT> and <EMBED> labels.
(3) Insert id = "myFlash" in the object tag"

<Object classid = "clsid: D27CDB6E-AE6D-11cf-96B8-444553540000"
Codebase = "http://download.macromedia.com/pub/shockwave/cabs/
Flash/swflash. cab # version = 5, 0, 0"
Width = 366 height = 142 id = "myFlash">
Note: If you paste and copy the code, make sure to delete unnecessary line breaks. Otherwise, errors may occur. You can also directly enter the id in the property panel.
(4) Insert name = "myFlash" and swLiveConnect = "true" in the EMBED label to ensure that the id attribute is not used! The Code should be like this:

<Embed src = "javascript_to_flash.swf" quality = high width = 366 height = 142
Type = "application/x-shockwave-flash" pluginspage = "http://www.macromedia.com/shockwave/download/index.cgi?
P1_Prod_Version = ShockwaveFlash"
Name = "myFlash" swLiveConnect = "true">
</Embed>

3. Create a form field
(1) return to the design view
(2) Insert a Text Field (Insert> Form Object> Text Field). If you want to add a Form Field, select Yes
(3) modify the HTML tag of the text field as follows:

<Input type = "text" name = "sendText" maxlength = "45" onChange = "doPassVar (this)">
When the content of the text field changes, onChange is triggered, and the doPassVar () function is called.

4. Create a Javascript function that passes variable values
Copy the following Javascript code to the

<Script language = JavaScript>
<! --
Function doPassVar (args ){
Var sendText = args. value;
Optional variable Doc ument. myFlash. SetVariable ("myVar", sendText );
}
// -->
</SCRIPT>
5. Save the file and test it (F12)

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.