Communication of JavaScript and Flash

xiaoxiao2021-03-06  69

Explanation: Slightly modified, mainly some primary operations; there are many similar articles, but this is very authoritative

Here are some examples of direct communication directly in Flash and HTML files using JavaScript, each example has a brief step.

This article discusses three basic Flash / JavaScript communication methods:> JavaScript to flash communication ---- JavaScript method using Flash Player> Flash to JavaScript communication ---- using Flash FSCommand> Flash to Flash communication ----------- 2 techniques using local connection objects or synthesis

Not all browsers pay great attention to scripts. In order to communicate with the flash player, the browser must have built-in hooks so that the Flash player can 'listen ". The browser must be the following:> Netscape Navigator 3.0-4.7x And Netscape 6.2 or higher (Windows 95/98 / NT / 2000 / XP or MacOS; allowed Java and LiveConnect)> Internet Explorer 3.0 or higher (only Windows 95/98 / NT / 2000 / XP; allowed ActiveX)

Note: This approach is not supported by Internet Explorer and earlier versions on Macintosh. Please check the additional information from this article.

JavaScript to Flash communication This example demonstrates how to use Flash Method to send variables from HTML's INPUT text to the flash file in this page. HTML INPUT data is transferred to the flash file via Flash's setvariable method.

View example: sample Download Source File (17K)

Steps:> Flash 1. Create a file to be saved as JavaScript_to_flash.fla 2. Create a text domain on the stage 3. Select this text field, select Dynamic Text from the Distribution List (Dynamic Text ), Fill in the variable bar "Note: The best habit is to use instance, change myvar's value with myvar.text. For simple start and compatible with Flash4 and Flash5, we use the form of variable names. 4. Save File 5. Publish HTML files and SWF files

> Dreamweaver's next work is transferred to Dreamweaver, of course, other HTML editors 1. Open the HTML file published on the previous step 2. Insert the generated SWF file and Object / Embed tab (1) Insert> Media> Flash, and select this flash (2) to switch to the code view, we need to modify the selected and tab (3) in the Object tab, insert id = "Myflash"

Note: If you are paste the copy code, make sure to delete unnecessary wraps. Otherwise, an error may be caused; ID can also be directly entered directly (4) in the Embed tab, insert Name = "Myflash" and swwliveConnect = " True, make sure not use ID attributes! The code should be like this: 3. Creating a form field (1) Back to design view (2) Insert a text domain (INSERT> Form Object> Text Field), if you ask if you add a form field, choose Yes (3) Modify the HTML tag of the text domain to this:

Whenever the text domain changes, the onchange is triggered, and the DOPASSVAR () function is called.

4. Create a JavaScript function that delivers the variable value Copy the following JavaScript to tab