如何从 javascript 启动 Flash 视频?
是否可以使用 javascript 代码在 Flash 播放器中开始播放文件? 如果是这样,我该怎么做?
Is it possible to start playing a file inside a flash player by making use of javascript code? If so, how would I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试使用swfObject,您可以使用
ExternalInterface
使任何actionscript函数对javascript可见并将它们声明为 javascript。 因此,您可以使用 JavaScript 代码中的play()
(或您想要的任何其他代码)触发 ActionScript 函数。下面是一个示例:
Actionscript:
Javascript:
其中 methodName 是 js 用于从 Actionscript 调用方法的标识符。
Try using swfObject, you can make any actionscript function visible for javascript using
ExternalInterface
and declaring them into javascript. So you can trigger actionscript function withplay()
(or any other code you want) from your javascript code.Here is an example:
Actionscript:
Javascript:
Where methodName is the identifier js uses to call the method from actionscript.
看一下 SWFObject。 有很多关于如何实现这一目标的示例。
Take a look at SWFObject. There a lot of examples on how to accomplish that.
是的。 您可以从js中引用flash影片对象并控制页面中的flash组件。 不幸的是,你这样做的方式不能跨浏览器移植。 请参阅:
http://www.permadi.com/tutorial/flashjscommand/
Yes it is. You can reference the flash movie objects from js and control the flash component in a page. Unfortunately the way you do it is not portable across browsers. See this:
http://www.permadi.com/tutorial/flashjscommand/
如果您必须从 Javascript 执行此操作,请考虑打开自动播放参数,如下所示:
假设您已获取对象/嵌入的父级 ( vidParent ):
这将使用 autoplay = 1 重新加载 Flash(此示例适用于 YouTube 播放器) )。
我必须这样做才能对视频播放进行一些跟踪。
If you HAVE to do it from Javascript consider flipping ON the autoplay parameter like so:
Assuming you've grabbed the parent of the object/embed ( vidParent ):
This will reload the flash with autoplay = 1 ( this example works with the YouTube player ).
I had to do this to do some tracking on video plays.
这里建议一个有趣的方法:http://www.permadi.com/tutorial/flashjscommand/
对我有用!
这个想法是使用
embed
对象并随后调用其
Play()
方法。支持其他几种方法,请参阅上面的链接。
An interesting method is suggested here: http://www.permadi.com/tutorial/flashjscommand/
Works for me!
The idea is to get
embed
object usingand to call its
Play()
method afterwards.A couple of other methods are supported, see the link above.
您可以从 JavaScript 调用 Flash 中的任何自定义函数,这需要您同时编写 Javascript 和 Flash 代码。
请参阅此处的一些示例:http://kb.adobe.com/selfservice/ viewContent.do?externalId=tn_15683。
此外,使用 SwfObject 在通过 JavaScript 处理 Flash 时有很大帮助。
You can call any custom function in Flash from JavaScript, which requires you coding both Javascript and Flash.
See here for some examples: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683.
Also, using SwfObject helps a long way when dealing with Flash from JavaScript.