用 javascript + actionScript 解决透明的flash在firefox上滚轮失效的有关问题
用 javascript + actionScript 解决透明的flash在firefox下滚轮失效的问题!1、在flash的宿主文件(HTML)下增
用 javascript + actionScript 解决透明的flash在firefox下滚轮失效的问题!
1、在flash的宿主文件(HTML)下增加如下代码:
[javascript] view plaincopy
- <mce:script?language="JavaScript"?type="text/javascript"><!--??????if(!(document.attachEvent))?{??
- ????????window.addEventListener("DOMMouseScroll",?handleWheel,?false);??????}??
- ????function?handleWheel(event)?{??????????var?app?=?window.document["${application}"];??
- ????????if?(app)?{??????????????var?o?=?{x:?event.screenX,?y:?event.screenY,??
- ????????????????delta:?event.detail,??????????????????ctrlKey:?event.ctrlKey,?altKey:?event.altKey,??
- ????????????????shiftKey:?event.shiftKey}???????????????
- ????????????app.handleWheel(o);??????????}??
- ????}??//?--></mce:script>??
注,${application}为FLEX站点工程下XXX.template的参数,如为其他文件,请改为flash对象的ID值。
?
2、在flash程序初始化完后,执行此代码:
[javascript] view plaincopy
- ExternalInterface.addCallback("handleWheel",?handleWheel);??
注:可以把这行代码加入初始化完成的事件回调函数中执行,此函数注册来自javascript函数"handleWheel"的事件,回调函数是handleWheel,此函数代码如下:
?
3、在上面这句代码的函数外,加入此函数:
[javascript] view plaincopy
- public?function?handleWheel(event:Object):?void?{??????var?obj:InteractiveObject?=?null;??
- ????var?tmpGlbPoint:Point?=?new?Point(this.mouseX,?this.mouseY);??????var?objects:Array?=?this.getObjectsUnderPoint(tmpGlbPoint);??
- ????for?(var?i:int?=?objects.length?-?1;?i?>=?0;?i--)?{??????????if?(objects[i]?is?InteractiveObject)?{??
- ????????????obj?=?objects[i]?as?InteractiveObject;??????????????break;??
- ????????}?else?{??????????????if?(objects[i]?is?Shape?&&?(objects[i]?as?Shape).parent)?{??
- ????????????????obj?=?(objects[i]?as?Shape).parent;??????????????????break;??
- ????????????}??????????}??
- ????}??????if?(obj)?{??
- ????????var?tmpP:Point?=?obj.globalToLocal(tmpGlbPoint);??????????var?mEvent:MouseEvent?=?new?MouseEvent(MouseEvent.MOUSE_WHEEL,?true,?false,??
- ????????????tmpP.x,?tmpP.y,?obj,??????????????event.ctrlKey,?event.altKey,?event.shiftKey,??
- ????????????false,?-Number(event.delta));??????????obj.dispatchEvent(mEvent);??
- ????}??}?