Flash对象上的javascript onclick事件 [英] javascript onclick event over flash object

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

问题描述

我在一个 div 中嵌入了一个 Flash 电影,我在主 div 中放置了一个 javascript onclick 事件处理程序,但没有捕捉到点击,有什么问题吗?

代码:

 

<对象宽度=400"高度=300"><param name="电影" value="general.swf"><embed src="./swf/general.swf" width="400" height="300"></嵌入></对象>

解决方案

最好将所有 swf 视为具有无穷大的 z 顺序.闪存是最重要的,几乎没有什么可以阻止它.另一方面,如果您可以访问 SWF 本身的代码,或者如果您可以使用另一个 swf 加载您当前的 swf,您将能够使用几个不同的 Flash 命令来处理页面的 JavaScript.(ExternalInterface 是您最好的选择).

//这就是你的AS代码应该是这样的:导入 flash.external.ExternalInterface;导入 flash.events.MouseEvent;root.addEventListener( MouseEvent.CLICK, useExternal, true );函数 useExternal( event:MouseEvent):void{//swfClickFunction 是在 JavaScript 中定义的ExternalInterface.call("swfClickFunction");}

下面的 Darwin 提供了另一种使用 onmousedown 代替 onclick 的替代解决方案.

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天全站免登陆