如何通过Javascript与Flash进行交互? [英] How to interact with Flash via Javascript?

查看:172
本文介绍了如何通过Javascript与Flash进行交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在有一个非常基本的Flash项目,连接到一个RTMP服务器,并从网络摄像头流式传输视频和音频。它创建一个具有特定名称的用户流。



在同一个项目中还有一个其他实体可以流式传输的流名称的输入。因此,您可以使用Skype与Flash进行视频聊天。



在Flash中,我可以控制何时开始发布自己的视频流以及何时播放其他视频流。

我想知道如何通过Javascript控制Flash函数(StartPublish,StartStream等)。我在看 http://osflash.org/projects/flashjs ,想知道我是否在正确的路径。

解决方案

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html



ExternalInterface类是专门为此目的而设计的。这是一个相对简单的类暴露动作的JS功能,反之亦然。我最近在一个音频播放器中实现了它,我的团队开发了一个HTML格式的曲目列表触发器,并停止事件。

基本上,您可以先对代码进行检查c $ c> ExternalInterface.available 来确保容器具有外部接口(IE浏览器窗口中的JavaScript,而不仅仅是从flash播放器运行)。从那里,你可以使用 addCallback 来指定一个函数,然后可以在Flash小程序的容器上调用。



然后,可以使用典型的javascript - 只需使用getElementByID访问容器的方法,或者如果您使用的是框架,则选择任何您喜欢的选择器。



确保您的嵌入方法允许脚本访问flash小程序也是如此。


At this moment there is a very basic flash project that connects to a rtmp server and streams video&audio from webcam. It creates a stream from a user with a certain name.

Also in same project there is an input for a stream name that other entity can stream. Therefore you get Skype alike video-chat with flash.

In flash I can control when I want to start publishing own stream and when want to play someone else's stream.

I am trying to figure out how I can control Flash Functions (StartPublish, StartStream, etc) via Javascript.

I am looking at http://osflash.org/projects/flashjs and would like to know if I am on right path.

解决方案

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html

The ExternalInterface class is designed specifically for this purpose. It's a relatively simple class for exposing actionscript functions to JS or vice versa. I recently implemented it in an audio player my team developed to have an HTML formatted tracklist trigger play and stop events.

Essentially, you can make your code first check against ExternalInterface.available to make sure the container has an external interface (IE in a browser window with javascript and not just running from flash player.) From there, you can use addCallback to designate a function that can then be called on the flash applet's container.

You can then call it using the typical javascript - just access the method off of the container using getElementByID or whatever selector flavor you prefer if you're using a framework.

Make sure your embed method allows script access to the flash applet as well.

这篇关于如何通过Javascript与Flash进行交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆