如何让我的Flash对象得到重点加载? [英] How do I make my flash object get focus on load?

查看:99
本文介绍了如何让我的Flash对象得到重点加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图为我的Flash游戏设置这个测试页面,但是它拒绝专注于加载。我读了一大堆论坛作品,没有做任何事情,我真的不相信这应该是如此艰难。



以下是我的:

 < head> 
< title>在这里,我们退出了RAT RACE< / title>
< meta http-equiv =Content-Typecontent =text / html; charset = iso-8859-1/>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js>< / script>
< script type =text / javascript>
swfobject.embedSWF(UpHere.swf,myContent,700,300,9.0.0);

函数setFocusOnFlash(){
var fl = document.getElementById(myContent);
if(fl){fl.focus(); }
}
< / script>
< / head>
< body onload =setFocusOnFlash()>
< div style =margin:0 auto; text-align:center; width:700px;>
< div id =myContentstyle =margin:0 auto; text-align:center; width:700px;>
< p>替代内容< / p>
< / div>
< / div>
< / body>

你可以在这里看到它,
http://joon.be/exclusivepreview/

它有什么问题?
我对swfObject没有深入的了解...

解决方案

我找到了一个可行的方法对于我在Firefox 16,Chrome 23和IE 8(这些都是我迄今测试过的地方)。当然,这是一堆黑客,所以谁知道它是否会永久工作...但它肯定不会让事情变得更糟。

  function setFocusOnFlash(){
var flash = document.getElementById(theIdOfTheObjectElement);
flash.tabIndex = 1234; Chrome 23
flash.focus();
//注意:FireFox需要wmode不透明!





仅在Firefox上,< param name =在对象元素下也需要wmodevalue =opaque> ,否则 code>没有效果。 (我已经使用了Stephen Belanger的 jquery.flash ,您可以在其中指定 wmode ;我也可以用 SWFObject 。)

但是更棘手的是你不能调用 setFocusOnFlash 太早了。对于Chrome和IE,在插入对象的JavaScript已经工作之后直接添加 setTimeout(setFocusOnFlash,1)。直接发行 setFocusOnFlash()没有。我假设的是,只有在浏览器完全处理了文档更改之后才调用定时回调,而不管您指定的延迟。但在Firefox这个小的延迟调用还为时过早,它已经在对象元素周围加了一个虚线的边框(它不应该),而Flash没有得到关键的笔划。将延迟设置为250已经在我的电脑上解决了这个问题,但谁知道你需要多大的延迟。 (更糟糕的是,重复 setFocusOnFlash 调用也没有帮助...一旦有虚线边框在那里,他们没有进一步的影响。)所以,我所做的,一个 ExternalInterface.call(flashLoaded)回调到 flash 文档类的构造函数。要清楚的是,你在Flash / ActionScript中这样做,所以你需要访问源或SWF文件的作者。这样,当SWF启动时,它将调用嵌入HTML页面的 flashLoaded JavaScript方法,以便您知道它已准备就绪。这个函数是这样的:

pre $函数flashLoaded(){
//奇怪的是,直接调用setFocusOnFlash()没有工作在IE8
setTimeout(setFocusOnFlash,1);
}


I've been trying to set up this test page for my flash game but it refuses to gain focus on load. I read a bunch of forum entries and didn't get it to do anything, I can't really believe this should be so hard.

Here's what I have:

  <head>
<title>UP HERE WE ESCAPE THE RAT RACE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">
    swfobject.embedSWF("UpHere.swf", "myContent", "700", "300", "9.0.0");

    function setFocusOnFlash() { 
    var fl = document.getElementById("myContent"); 
      if (fl) { fl.focus(); } 
    } 
</script>
  </head>
  <body  onload="setFocusOnFlash()">
  <div style="margin:0 auto; text-align:center; width:700px;">
    <div id="myContent" style="margin:0 auto; text-align:center; width:700px;">
      <p>Alternative content</p>
    </div>
     </div>
      </body>

You can see it live here, http://joon.be/exclusivepreview/

what's wrong with it? I don't have a very deep knowledge of swfObject...

解决方案

I have found a way that works for me on Firefox 16, Chrome 23 and IE 8 (these are where I have tested it so far). Of course, this is a bunch of hacks so who knows if it will work forever... but it certainly doesn't make things worse.

function setFocusOnFlash() {    
    var flash = document.getElementById("theIdOfTheObjectElement");
    flash.tabIndex = 1234;  // This was needed on Chrome 23
    flash.focus();
    // Attention: FireFox needs wmode "opaque"!
}

On Firefox only, <param name="wmode" value="opaque"> under the object element was also needed, or else focus() had no effect. (I have used Stephen Belanger's jquery.flash, where you can specify wmode; I assume it's also possible with SWFObject.)

But the trickier part is that you must not call setFocusOnFlash too early. For Chrome and IE, adding setTimeout(setFocusOnFlash, 1) directly after the JavaScript that inserts the object has worked. Directly issuing setFocusOnFlash() didn't. I assume the trick is simply that the timed callbacks are only called after the browser has fully processed the document change, regardless of the delay you specify. But on Firefox calling with this small delay was too early; it has put a dotted border around the object element (it shouldn't) and Flash didn't get the key strokes. Setting the delay to 250 has fixed this on my computer, but who knows how big delay you need. (Worse, repeating the setFocusOnFlash calls didn't help either... once that dotted border was there, they had no further effect.) So, what I did instead is adding an ExternalInterface.call("flashLoaded") callback to the flash document class constructor. To be clear, you do that in Flash/ActionScript, so you need access to the source or to the author of the SWF file. This way, when the SWF starts, it calls the flashLoaded JavaScript method of the embedding HTML page, so you know it's ready. The function was like:

function flashLoaded() {
    // Oddly, directly calling setFocusOnFlash() didn't work on IE8
    setTimeout(setFocusOnFlash, 1);
}

这篇关于如何让我的Flash对象得到重点加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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