An example of communication between Macromedia Flash 5 movies through JavaScript
Below are examples of communication between Macromedia Flash movies in an HTML document using JavaScript, followed by steps to recreate each.
This TechNote builds on information found in An example of communication between JavaScript and Flash (TechNote 15683), which explains how to usefscommand and Flash's JavaScript methods to send messages from a Flash movie to the host environment (Web browser) and vice versa. Below, these two techniques are combined to facilitate communication between two separate Flash movies in the same HTML page. Experienced scripters should first read the article Scripting with Flash for an overview of JavaScript methods which can control the Flash Player.
Note : Browser scripting is not a feature of all browsers. In order to communicate with the Flash Player the browser must have built in hooks which the Flash Player can 'listen' to. This is especially problematic for Internet Explorer on the Macintosh. For details see Flash and Internet Explorer Issues on the Macintosh Platform (TechNote 13638) as well as Netscape 6, 6.01 and Mozilla (Technote 14625). Specifically, these examples and techniques require:
| |
Netscape Navigator 3.0 to 4.7x (LiveConnect and Java-enabled; Windows 95/98/NT/2000/XP or MacOS) |
| |
Netscape 6.2 or higher (LiveConnect and Java-enabled; Windows 95/98/NT/2000/XP or MacOS) |
| |
Internet Explorer 3.0 and above (ActiveX enabled; Windows 95/98/NT/2000/XP only) |
Note: Browser scripting for Netscape 6.2 and above requires theNAME attribute of the Object tag to be removed. Netscape 6.2, 7 or higher will not allow script communication if the NAME parameter is in the Object tag. The ID attribute of the Object tag is still required for Internet Explorer compabitility (and is ignored by Netscape).
Flash-to-Flash communication
In his example, text entered in one Flash movie is sent to another Flash movie embedded in the same HTML document.
SeeExample 1 to view a working demonstration of this technique.
Download the source files for this example flash_to_flash.zip (24K).
| |
In Flash 1 Create a new file in Flash and save it as
Add a text field to the stage using the Text Tool. 3 Select the text field and open the Text Options panel (Window> Panels> Options). 4 In the Text Options Panel type the variable name
On the Object Actions panel for the button paste or add the following actions: Choose File> Export Movie and export the file as 1 Create a new file in Flash and save it as Place a text field on the stage using the Text Tool. 3 Select the text field and open the Text Options panel (Window> Panels> Options) 4 In the Text Options Panel type the variable name Save the Flash file. 6 Choose File> Export Movie and export the file as |
| |
In Dreamweaver 4.0
1 Open a new HTML file by choosing File> New. Save the document to the same folder that contains the Flash movies created above. 2 Choose Insert> Media> Flash and insert In the Document window, select the placeholder area for
Note: For Netscape 6.2 and above this functionality requires the NAME attribute of the Object tag to be removed. Netscape 6.2, 7 or higher will not allow script communication if the NAME parameter is in the Object tag. The ID attribute of the Object tag is still required for Internet Explorer compabitility (and is ignored by Netscape). 4 Select the placeholder for receive_from_flash.swf and, also in the Property Inspector, enter the valueget_var into the same Name and ID fields. 5 Launch the Code Inspector, or switch to Code view, to view the HTML source code. 6 In the HTML source, add the <embed href="/support/flash/ts/documents/filename.swf" quality=high bgcolor=#FFFFFF width=300 height=200 swliveconnect=true>
Note : The example will not work in Netscape browsers unless the Paste the following JavaScript code into the HTML source directly after the opening <SCRIPT LANGUAGE=JavaScript><!-- var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1; function send_to_flash_DoFSCommand(command, args) { window.document.get_var.SetVariable("displayVar", args); } if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) { document.write('<SCRIPT LANGUAGE=VBScript\> \n'); document.write('on error resume next \n'); document.write('Sub send_to_flash_FSCommand(ByVal command, ByVal args)\n'); document.write(' call send_to_flash_DoFSCommand(command, args)\n'); document.write('end sub\n'); document.write('</SCRIPT\> \n'); } //--></SCRIPT>
8 Choose File> Save. 9Choose File> Preview in Browser and choose a browser, or press F12. |
Additional information
For more detailed information about making the communication between Flash and JavaScript, please consult An example of communicating between Javascript and Flash (TechNote 15683)
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!

