通过Flash对象的JavaScript onclick事件 [英] javascript onclick event over flash object

查看:343
本文介绍了通过Flash对象的JavaScript onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌入Flash影片里面一个div,我把一个JavaScript onclick事件处理程序在主div,但没有捕捉点击,有什么错?



代码:

 < div id =top-box-playeronclick =alert('Hi Bananas! );> 
< object width =400height =300>
< param name =movievalue =general.swf>
< embed src =./ swf / general.swfwidth =400height =300>
< / embed>
< / object>
< / div>


解决方案

最好把所有的swf想象成一个无限的z阶。 Flash是最重要的,而且可以做的很少。另一方面,如果您有权访问SWF本身的代码,或者如果您可以使用其他swf来加载当前的swf,则可以使用几个不同的Flash命令来解决页面的JavaScript问题。 (ExternalInterface是你最好的选择)。

  //这是你的AS代码的样子:
import flash .external.ExternalInterface;
import flash.events.MouseEvent;

root.addEventListener(MouseEvent.CLICK,useExternal,true); b








$ b $外部接口(swfClickFunction)定义的函数useExternal(event:MouseEvent)





$ b另一种使用onmousedown替代onclick的解决方案是由Darwin在下面提供的。

I have one embed flash movie inside one div, I put one javascript onclick event handler in the main div, but isn't catching the click, what is wrong?

Code:

   <div id="top-box-player" onclick="alert('Hi Bananas!');">
     <object width="400" height="300">
        <param name="movie" value="general.swf">
        <embed src="./swf/general.swf" width="400" height="300">
        </embed>
     </object>
   </div>

解决方案

It is best to think of all swf's as having a z-order of infinity. Flash is on top and there is very little which can be done to stop that. On the other hand, if you have access to the code of the SWF itself, or if you can use another swf to load your current swf, you'll be able to use a couple of different Flash commands to address the JavaScript of the page. (ExternalInterface is your best bet).

//This is what your AS code should look like:
import flash.external.ExternalInterface;
import flash.events.MouseEvent;

root.addEventListener( MouseEvent.CLICK, useExternal, true );

function useExternal( event:MouseEvent):void
{
    //swfClickFunction is defined in JavaScript
    ExternalInterface.call( "swfClickFunction" );
}

Another alternative solution using onmousedown instead of onclick is provided by Darwin below.

这篇关于通过Flash对象的JavaScript onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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