[ActionScript] AS3解决html与flash鼠标滚轮冲突的问题
2015-09-04 13:08
549 查看
JS端:
AS端:
<script type="text/javascript"> <!-- var winWidth = 0; var winHeight = 0; var scrHeight = 0; function findDimensions() //函数:获取尺寸 { //获取窗口宽度 if (window.innerWidth) winWidth = window.innerWidth; else if ((document.body) && (document.body.clientWidth)) winWidth = document.body.clientWidth; //获取窗口高度 if (window.innerHeight) winHeight = window.innerHeight; else if ((document.body) && (document.body.clientHeight)) winHeight = document.body.clientHeight; //通过深入Document内部对body进行检测,获取窗口大小 if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) { winHeight = document.documentElement.clientHeight;//窗口的高度 winWidth = document.documentElement.clientWidth; } //scrHeight = document.documentElement.scrollTop;//滚去的高度 scrHeight = getScrollTop();//滚去的高度 sendToActionScript(winWidth+"_"+winHeight+"_"+scrHeight);//alert(winWidth+"_"+winHeight+"_"+scrHeight); } //findDimensions(); //调用函数,获取数值 window.onresize=findDimensions; window.onscroll=findDimensions; //window.onload = findDimensions; //setTimeout("sendToActionScript(winWidth+'_'+winHeight+'_'+scrHeight)",5000); //setTimeout("findDimensions()",5000); /** * 获取滚动条距离顶端的距离 * @return {}支持IE6 火狐 谷歌浏览器 */ function getScrollTop() { var scrollPos; if (window.pageYOffset) { scrollPos = window.pageYOffset; } else if (document.compatMode && document.compatMode != 'BackCompat') { scrollPos = document.documentElement.scrollTop; }else if (document.body) { scrollPos = document.body.scrollTop; } return scrollPos; } function thisMovie(movieName) { if (navigator.appName.indexOf("Microsoft") != -1) { return window[movieName]; } else { return document[movieName]; } } function sendToActionScript(value) { thisMovie("FlashAndHtmlWheelConflict").sendToActionScript(value); } function wheelToFlash(boolean){ if(boolean){ disabledMouseWheel(); }else{ window.onmousewheel = document.onmousewheel = findDimensions; } } /** * 禁用鼠标滚轮事件 * @return {}支持ie9、chrome、opera Firefox */ function disabledMouseWheel() { if (document.addEventListener) { document.addEventListener('DOMMouseScroll', scrollFunc, false); }//W3C window.onmousewheel = document.onmousewheel = scrollFunc;//IE/Opera/Chrome } function scrollFunc(evt) { evt = evt || window.event; if(evt.preventDefault) { // Firefox evt.preventDefault(); evt.stopPropagation(); } else { // IE evt.cancelBubble=true; evt.returnValue = false; } return false; } //window.onload=disabledMouseWheel; //--> </script>
AS端:
package { import flash.display.DisplayObjectContainer; import flash.display.Sprite; import flash.events.MouseEvent; import flash.external.ExternalInterface; import flash.text.TextField; /** * @author Frost.Yen * @E-mail 871979853@qq.com * @create 2015-9-4 上午12:11:13 * */ [SWF(height="1000",width="800")] public class FlashAndHtmlWheelConflict extends Sprite { private var _t:TextField; private var _wheelH:Number = 0; private var _htmlW:Number; private var _htmlH:Number; private var _scrollH:Number; private var _sp1:Sprite; private var _sp2:Sprite; public function FlashAndHtmlWheelConflict() { init(); external(); } private function init():void { _t = new TextField(); _t.autoSize = "left"; this.addChild(_t); this.graphics.beginFill(0xff00ff,0.5); this.graphics.drawRect(0,0,800,1000); _sp1 = new Sprite(); _sp2 = new Sprite(); _sp1.graphics.beginFill(0x00ff00); _sp1.graphics.drawRect(0,0,300,500); _sp1.graphics.endFill(); this.addChild(_sp1); _sp2.graphics.beginFill(0x00ff00); _sp2.graphics.drawRect(0,0,300,500); _sp2.graphics.endFill(); this.addChild(_sp2);_sp2.x = 400; _sp1.addEventListener(MouseEvent.MOUSE_WHEEL,onMouseWheel1); _sp2.addEventListener(MouseEvent.MOUSE_WHEEL,onMouseWheel2); } private function external():void { if (ExternalInterface.available) { try { ExternalInterface.addCallback("sendToActionScript", onResize); } catch(error:Error) { trace("Error: " + error); } catch(secError:SecurityError) { trace("Security error: " + secError); } } else { trace("ExternalInterface is not available"); } } private function onResize(value:String):void { _htmlW = Number(value.split("_")[0]); _htmlH = Number(value.split("_")[1]); _scrollH = Number(value.split("_")[2]); _t.text = "html窗口width:"+_htmlW+"--html窗口height"+_htmlH+"--html滚动height"+_scrollH+"--flash滚动height"+_wheelH; _t.x = (stage.stageWidth - _t.width)*.5; _t.y = (stage.stageHeight - _t.height)*.5; } private function onMouseWheel1(e:MouseEvent):void { _wheelH += e.delta; trace(e.delta,"e.delta"); _t.text = "html窗口width:"+_htmlW+"--html窗口height"+_htmlH+"--html滚动height"+_scrollH+"--flash滚动height"+_wheelH; _t.x = (stage.stageWidth - _t.width)*.5; _t.y = (stage.stageHeight - _t.height)*.5; ExternalInterface.call("wheelToFlash",true); } private function onMouseWheel2(e:MouseEvent):void { ExternalInterface.call("wheelToFlash",false); } private function wheelToFlash(target:DisplayObjectContainer):void { } } }
相关文章推荐
- html name id, 与服务器交互必须有name
- html name id, 与服务器交互必须有name
- html中有关如何固定div大小的问题
- st-在html中添加数据总结
- html 文本标签
- html 小知识
- outlook HTML签名制作方法
- 认识html标签
- WEB入门——HTML
- 动态输出html一些效果失效的处理
- 动态输出html一些效果失效的处理
- html meta link script form
- 在HTML中打出人民币符号和对勾符号
- 在HTML中打出人民币符号和对勾符号
- html中表table行循环滚动例子
- 使用GET与POST方式获取html数据
- 将html导出到excel或word
- HTML中id,name,class的区别
- html经验
- uploadify 上传插件的使用(视频和图片都可以上传)