如何从 javascript 启动 Flash 视频?

发布于 2024-07-15 23:46:47 字数 60 浏览 12 评论 0原文

是否可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

妖妓 2024-07-22 23:46:47

尝试使用swfObject,您可以使用ExternalInterface使任何actionscript函数对javascript可见并将它们声明为 javascript。 因此,您可以使用 JavaScript 代码中的 play() (或您想要的任何其他代码)触发 ActionScript 函数。

下面是一个示例:

Actionscript:

import flash.external.ExternalInterface;

ExternalInterface.addCallback( "methodName", this, method );
function method() {
   trace("called from javascript");
}

Javascript:

function callAS() {
   swf.methodName(); 
}

其中 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 with play() (or any other code you want) from your javascript code.

Here is an example:

Actionscript:

import flash.external.ExternalInterface;

ExternalInterface.addCallback( "methodName", this, method );
function method() {
   trace("called from javascript");
}

Javascript:

function callAS() {
   swf.methodName(); 
}

Where methodName is the identifier js uses to call the method from actionscript.

饭团 2024-07-22 23:46:47

看一下 SWFObject。 有很多关于如何实现这一目标的示例。

Take a look at SWFObject. There a lot of examples on how to accomplish that.

女皇必胜 2024-07-22 23:46:47

是的。 您可以从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/

酒中人 2024-07-22 23:46:47

如果您必须从 Javascript 执行此操作,请考虑打开自动播放参数,如下所示:

假设您已获取对象/嵌入的父级 ( vidParent ):

if( document.all) {
  // toggle the object code (IE)
  vidParent.innerHTML = vidParent.innerHTML.replace(/0\" name=\"autoplay/gi,'1\" name=\"autoplay');
} else {
  // toggle the embed code
  vidParent.innerHTML = vidParent.innerHTML.replace(/autoplay=0/gi,'autoplay=1'); 
}

这将使用 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 ):

if( document.all) {
  // toggle the object code (IE)
  vidParent.innerHTML = vidParent.innerHTML.replace(/0\" name=\"autoplay/gi,'1\" name=\"autoplay');
} else {
  // toggle the embed code
  vidParent.innerHTML = vidParent.innerHTML.replace(/autoplay=0/gi,'autoplay=1'); 
}

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.

丶情人眼里出诗心の 2024-07-22 23:46:47

这里建议一个有趣的方法:http://www.permadi.com/tutorial/flashjscommand/

对我有用!

这个想法是使用 embed 对象

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

并随后调用其 Play() 方法。

getFlashMovieObject('MyMovie').Play()

支持其他几种方法,请参阅上面的链接。

An interesting method is suggested here: http://www.permadi.com/tutorial/flashjscommand/

Works for me!

The idea is to get embed object using

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

and to call its Play() method afterwards.

getFlashMovieObject('MyMovie').Play()

A couple of other methods are supported, see the link above.

好听的两个字的网名 2024-07-22 23:46:47

您可以从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文