简体   繁体   English

如何检测Flash电影何时以Javascript代码为焦点?

[英]How to detect when a Flash movie gets focus in Javascript code?

Is it possible to create a such event? 是否可以创建这样的事件? If yes, how? 如果是,怎么办?

The markup for a flash movie is something like the next. Flash电影的标记类似于下一个。 Without changing ActionScript code of flash movie. 无需更改Flash电影的ActionScript代码。

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="32" height="32">
    <param name="movie" value="file://test.swf">
    <param name="quality" value="high">
    <embed src="file://test.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="32" height="32">
    </embed>
</object>

Yes, you can do so in JavaScript. 是的,您可以使用JavaScript进行操作。

First, it is a good idea to use swfobject to handle cross browser Flash issues. 首先,使用swfobject处理跨浏览器Flash问题是一个好主意。 This is a JavaScript library to control SWF objects. 这是一个用于控制SWF对象的JavaScript库。 You can download it here: https://code.google.com/p/swfobject/downloads/list 您可以在这里下载: https : //code.google.com/p/swfobject/downloads/list

Basic Example: 基本示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <title>SWFObject - low level dynamic publishing example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">
    if (swfobject.hasFlashPlayerVersion("6.0.0")) {
      var fn = function() {
        var att = { data:"test.swf", width:"780", height:"400" };
        var par = { flashvars:"foo=bar" };
        var id = "replaceMe";
        var myObject = swfobject.createSWF(att, par, id);
      };
      swfobject.addDomLoadEvent(fn);
    }
    </script>
  </head>
  <body>
    <div id="replaceMe">Alternative content</div>
  </body>
</html>

Next, just expand the example with an id inside the att variable like so: 接下来,只需在att变量中使用id扩展示例,如下所示:

var att = { data:"test.swf", width:"780", height:"400", id:"myId" };

You can access the object with getElementById() or a jQuery selector $("#myId") 您可以使用getElementById()或jQuery选择器$("#myId")访问对象

Then attach an event to on focus like so: 然后将事件附加到焦点上,如下所示:

JQuery: (recommended) jQuery :(推荐)

$('#myId').focus(function() {
  alert('SWF is in focus');
});

or 要么

Standard: 标准:

object.onfocus=function(){ alert('SWF is in focus'); }

You can place the player in a div, and select the div using javascipt. 您可以将播放器放在div中,然后使用javascipt选择div。 Also there is a more info here: https://github.com/englandrp/Cross-browser-Flash-tabbing-and-focus-solution 这里还有更多信息: https//github.com/englandrp/Cross-browser-Flash-tabbing-and-focus-solution

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM