search
HomeWeb Front-endJS TutorialBasic tutorial on interactive communication between Javascript and flash_javascript skills

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
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
es6数组怎么去掉重复并且重新排序es6数组怎么去掉重复并且重新排序May 05, 2022 pm 07:08 PM

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

JavaScript的Symbol类型、隐藏属性及全局注册表详解JavaScript的Symbol类型、隐藏属性及全局注册表详解Jun 02, 2022 am 11:50 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

原来利用纯CSS也能实现文字轮播与图片轮播!原来利用纯CSS也能实现文字轮播与图片轮播!Jun 10, 2022 pm 01:00 PM

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

JavaScript对象的构造函数和new操作符(实例详解)JavaScript对象的构造函数和new操作符(实例详解)May 10, 2022 pm 06:16 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

JavaScript面向对象详细解析之属性描述符JavaScript面向对象详细解析之属性描述符May 27, 2022 pm 05:29 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

javascript怎么移除元素点击事件javascript怎么移除元素点击事件Apr 11, 2022 pm 04:51 PM

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

整理总结JavaScript常见的BOM操作整理总结JavaScript常见的BOM操作Jun 01, 2022 am 11:43 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

foreach是es6里的吗foreach是es6里的吗May 05, 2022 pm 05:59 PM

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),