Home Web Front-end JS Tutorial Basic tutorial on interactive communication between Javascript and flash_javascript skills

Basic tutorial on interactive communication between Javascript and flash_javascript skills

May 16, 2016 pm 07:02 PM
flash javascript interaction

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

This article discusses 3 basic methods of Flash/Javascript communication:
Javascript to Flash Communication----Use Flash player's javascript method
Flash to Javascript communication----Use Flash's fscommand
Flash to Flash communication----------Use local connection object Or combine the above 2 technologies

Not all browsers attach great importance to scripts. In order to communicate with the Flash player, the browser must have a built-in hook 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; allows Java and LiveConnect)
Internet Explorer 3.0 or Higher
(Windows 95/98/NT/2000/XP only; ActiveX allowed)


Javascript to Flash communication

This example demonstrates how to use Flash methods Send variables from the HTML input text to the Flash file in the page. The HTML input data is sent to the Flash file through the SetVariable method of Flash.

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

Steps:

Flash
1. Create a new file and save it as javascript_to_flash.fla
2. Use the text tool to create a text field on the stage
3. Select this text field, in the properties panel, select Dynamic Text from the drop-down list, and fill in "myVar" in the variable column
Note: The best habit is to use Instance , 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 files and SWF files

In Dreamweaver
The next step of work is transferred to Dreamweaver, of course it can also be other HTML editors
1. Open the HTML file published in the previous step
2. Insert the generated SWF file and OBJECT /EMBED tag
(1) Insert>Media>Flash, and select this Flash
(2) Switch to the code view, we need to modify the selected and tags
(3) In the OBJECT tag, insert id="myFlash"

codebase="http://download.macromedia.com/ pub/shockwave/cabs/
flash/swflash.cab#version=5,0,0,0"
width=366 height=142 id="myFlash">
Note: If you paste and copy In terms of code, make sure to delete unnecessary line breaks. Otherwise, errors may occur; the id can also be entered directly in the properties panel
(4) In the EMBED tag, insert name="myFlash" and swLiveConnect="true" to ensure The id attribute is not used! The code should look like this:

type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?
P1_Prod_Version=ShockwaveFlash"
name="myFlash" swLiveConnect="true">


3. Create a form field
(1) Return to the design view
(2) Insert a text field (Insert> Form Object> Text Field). If asked whether to add a form field, choose yes
(3) Modify the HTML tag of the text field to this:


Whenever 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 into the tag



5. Save the file and test it (F12)


Flash to Javascript communication

You can send data from HTML to Flash, and vice versa. This example demonstrates how to use Flash's Fscommand to send data to Javascript.

View example: Example 2
Download source file: flash_to_javascript.zip (10K)

Brief steps:
Create a new file in Flash
and save it as flash_to_javascript.fla
Create a text field, set it to Input Text, select "border" so that we can see it, specify its variable as inputVar
Create a button, and add the following as on the button:

on (release) {
fscommand ("send_var", inputVar); <script> <BR><!-- <BR>function doPassVar(args){ <BR>var sendText = args.value; <BR>window.document.myFlash.SetVariable("myVar", sendText); <BR>} <BR>//--> <BR></script>}
保存文件,导出HTML和SWF

Dreamweaver中
1.打开导出HTML文件,修改标签,结果同上:
codebase="http://download.macromedia.com/pub/shockwave/cabs/
flash/swflash.cab#version=5,0,0,0"
width=366 height=142 id="myFlash">

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">

2. 插入如下的Javascript到标签内:
<script> <BR><!-- <BR>var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1; <BR>function myFlash_DoFSCommand(command, args) { <BR>var myFlashObj = InternetExplorer ? myFlash : document.myFlash; <BR>alert (args); <BR>} <BR>if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && <BR>navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) { <BR>document.write('<SCRIPT LANGUAGE=VBScript\> \n'); <BR>document.write('on error resume next \n'); <BR>document.write('Sub myFlash_FSCommand(ByVal command, ByVal args)\n'); <BR>document.write(' call myFlash_DoFSCommand(command, args)\n'); <BR>document.write('end sub\n'); <BR>document.write('</script>\> \n');

//-->



Flash和Flash的通信
通过上面两种方法的混和使用,同一HTML中两个或者更多的Flash直接可以相互传送消息. 从一个flash使用fscommand传送消息给Javascript,使用Flash的Javascript methods把消息传给另外一个flash

详细的看这里:Flash影片之间的通信示例

从Flash MX开始,local connection对象可以用来在flash之间传送消息. 这使得同一HTML中的或者位于两个浏览器窗口中的两个flash影片可以相互发送消息,而不必使用Javascript或者fscommand
详细的看这里:在Flash MX中使用local connection对象(英文)

本站的localConnection教程:http://www.blueidea.com/tech/multimedia/2003/739.asp

附可控制Flash Player的Javascript方法一览表:

Play() ---------------------------------------- 播放动画 
StopPlay()------------------------------------停止动画 
IsPlaying()----------------------------------- 动画是否正在播放
GotoFrame(frame_number)---------------- 跳转到某帧 
TotalFrames()------------------------------- 获取动画总帧数 
CurrentFrame()------------------------------回传当前动画所在帧数-1 
Rewind()-------------------------------------使动画返回第一帧 
SetZoomRect(left,top,right,buttom)-------放大指定区域 
Zoom(percent)------------------------------改变动画大小 
Pan(x_position,y_position,unit)------------使动画在x,y方向上平移 
PercentLoaded()----------------------------返回动画被载入的百分比 
LoadMovie(level_number,path)----------- 加载动画 
TGotoFrame(movie_clip,frame_number)- movie_clip跳转到指定帧数 
TGotoLabel(movie_clip,label_name)------ movie_clip跳转到指定标签 
TCurrentFrame(movie_clip)--------------- 回传movie_clip当前帧-1 
TCurrentLabel(movie_clip)-----------------回传movie_clip当前标签 
TPlay(movie_clip)---------------------------播放movie_clip 
TStopPlay(movie_clip)----------------------停止movie_clip的播放 
GetVariable(variable_name)-----------------获取变量 
SetVariable(variable_name,value)-----------变量赋值 
TCallFrame(movie_clip,frame_number)---call指定帧上的action 
TCallLabel(movie_clip,label)----------------call指定标签上的action 
TGetProperty(movie_clip,property)--------获取movie_clip的指定属性 
TSetProperty(movie_clip,property,number)-设置movie_clip的指定属性

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

Turn on split-screen interaction in win11 Turn on split-screen interaction in win11 Dec 25, 2023 pm 03:05 PM

In the win11 system, we can enable multiple monitors to use the same system and operate together by turning on split-screen interaction. However, many friends do not know how to turn on split-screen interaction. In fact, just find the monitor in the system settings. The following is Get up and study. How to open split-screen interaction in win11 1. Click on the Start menu and find "Settings" 2. Then find the "System" settings there. 3. After entering the system settings, select "Display" on the left. 4. Then select "Extend these displays" in the multi-monitor on the right.

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

JavaScript and WebSocket: Building an efficient real-time image processing system JavaScript and WebSocket: Building an efficient real-time image processing system Dec 17, 2023 am 08:41 AM

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data

See all articles