[ActionScript] AS3解决html与flash鼠标滚轮冲突的问题

JS端:

 1 <script type="text/javascript">
 2     <!--
 3         var winWidth = 0;
 4         var winHeight = 0;
 5         var scrHeight = 0;
 6         function findDimensions() //函数:获取尺寸
 7         {
 8              //获取窗口宽度
 9              if (window.innerWidth)
10                    winWidth = window.innerWidth;
11              else if ((document.body) && (document.body.clientWidth))
12                    winWidth = document.body.clientWidth;
13              //获取窗口高度
14              if (window.innerHeight)
15                    winHeight = window.innerHeight;
16              else if ((document.body) && (document.body.clientHeight))
17                    winHeight = document.body.clientHeight;
18
19              //通过深入Document内部对body进行检测,获取窗口大小
20              if (document.documentElement  && document.documentElement.clientHeight && document.documentElement.clientWidth)
21              {
22                  winHeight = document.documentElement.clientHeight;//窗口的高度
23                  winWidth = document.documentElement.clientWidth;
24
25              }
26
27             //scrHeight = document.documentElement.scrollTop;//滚去的高度
28             scrHeight = getScrollTop();//滚去的高度
29             sendToActionScript(winWidth+"_"+winHeight+"_"+scrHeight);//alert(winWidth+"_"+winHeight+"_"+scrHeight);
30         }
31         //findDimensions();                  //调用函数,获取数值
32         window.onresize=findDimensions;
33         window.onscroll=findDimensions;
34         //window.onload = findDimensions;
35         //setTimeout("sendToActionScript(winWidth+‘_‘+winHeight+‘_‘+scrHeight)",5000);
36         //setTimeout("findDimensions()",5000);
37         /**
38          * 获取滚动条距离顶端的距离
39          * @return {}支持IE6 火狐 谷歌浏览器
40          */
41         function getScrollTop() {
42             var scrollPos;
43             if (window.pageYOffset) {
44             scrollPos = window.pageYOffset; }
45             else if (document.compatMode && document.compatMode != ‘BackCompat‘)
46             {
47                 scrollPos = document.documentElement.scrollTop;
48             }else if (document.body) {
49                 scrollPos = document.body.scrollTop;
50             }
51             return scrollPos;
52         }
53         function thisMovie(movieName) {
54             if (navigator.appName.indexOf("Microsoft") != -1) {
55                 return window[movieName];
56             } else {
57                 return document[movieName];
58             }
59         }
60         function sendToActionScript(value) {
61             thisMovie("FlashAndHtmlWheelConflict").sendToActionScript(value);
62         }
63         function wheelToFlash(boolean){
64             if(boolean){
65                 disabledMouseWheel();
66             }else{
67                 window.onmousewheel = document.onmousewheel = findDimensions;
68             }
69         }
70
71         /**
72          * 禁用鼠标滚轮事件
73          * @return {}支持ie9、chrome、opera Firefox
74          */
75         function disabledMouseWheel() {
76             if (document.addEventListener) {
77                 document.addEventListener(‘DOMMouseScroll‘, scrollFunc, false);
78               }//W3C
79               window.onmousewheel = document.onmousewheel = scrollFunc;//IE/Opera/Chrome
80         }
81         function scrollFunc(evt) {
82               evt = evt || window.event;
83             if(evt.preventDefault) {
84                 // Firefox
85                   evt.preventDefault();
86                   evt.stopPropagation();
87             } else {
88                   // IE
89                   evt.cancelBubble=true;
90                   evt.returnValue = false;
91           }
92           return false;
93         }
94         //window.onload=disabledMouseWheel;
95     //-->
96     </script>

AS端:

 1 package
 2 {
 3     import flash.display.DisplayObjectContainer;
 4     import flash.display.Sprite;
 5     import flash.events.MouseEvent;
 6     import flash.external.ExternalInterface;
 7     import flash.text.TextField;
 8
 9     /**
10      * @author Frost.Yen
11      * @E-mail [email protected]
12      * @create 2015-9-4 上午12:11:13
13      *
14      */
15     [SWF(height="1000",width="800")]
16     public class FlashAndHtmlWheelConflict extends Sprite
17     {
18         private var _t:TextField;
19         private var _wheelH:Number = 0;
20         private var _htmlW:Number;
21         private var _htmlH:Number;
22         private var _scrollH:Number;
23
24         private var _sp1:Sprite;
25         private var _sp2:Sprite;
26         public function FlashAndHtmlWheelConflict()
27         {
28             init();
29             external();
30         }
31         private function init():void
32         {
33             _t = new TextField();
34             _t.autoSize = "left";
35             this.addChild(_t);
36             this.graphics.beginFill(0xff00ff,0.5);
37             this.graphics.drawRect(0,0,800,1000);
38             _sp1 = new Sprite();
39             _sp2 = new Sprite();
40             _sp1.graphics.beginFill(0x00ff00);
41             _sp1.graphics.drawRect(0,0,300,500);
42             _sp1.graphics.endFill();
43             this.addChild(_sp1);
44             _sp2.graphics.beginFill(0x00ff00);
45             _sp2.graphics.drawRect(0,0,300,500);
46             _sp2.graphics.endFill();
47             this.addChild(_sp2);_sp2.x = 400;
48             _sp1.addEventListener(MouseEvent.MOUSE_WHEEL,onMouseWheel1);
49             _sp2.addEventListener(MouseEvent.MOUSE_WHEEL,onMouseWheel2);
50         }
51         private function external():void
52         {
53             if (ExternalInterface.available)
54             {
55                 try
56                 {
57                     ExternalInterface.addCallback("sendToActionScript", onResize);
58                 }
59                 catch(error:Error)
60                 {
61                     trace("Error: " + error);
62                 }
63                 catch(secError:SecurityError)
64                 {
65                     trace("Security error: " + secError);
66                 }
67             }
68             else
69             {
70                 trace("ExternalInterface is not available");
71             }
72         }
73         private function onResize(value:String):void
74         {
75             _htmlW = Number(value.split("_")[0]);
76             _htmlH = Number(value.split("_")[1]);
77             _scrollH = Number(value.split("_")[2]);
78             _t.text = "html窗口width:"+_htmlW+"--html窗口height"+_htmlH+"--html滚动height"+_scrollH+"--flash滚动height"+_wheelH;
79             _t.x = (stage.stageWidth - _t.width)*.5;
80             _t.y = (stage.stageHeight - _t.height)*.5;
81         }
82         private function onMouseWheel1(e:MouseEvent):void
83         {
84             _wheelH += e.delta; trace(e.delta,"e.delta");
85             _t.text = "html窗口width:"+_htmlW+"--html窗口height"+_htmlH+"--html滚动height"+_scrollH+"--flash滚动height"+_wheelH;
86             _t.x = (stage.stageWidth - _t.width)*.5;
87             _t.y = (stage.stageHeight - _t.height)*.5;
88             ExternalInterface.call("wheelToFlash",true);
89         }
90         private function onMouseWheel2(e:MouseEvent):void
91         {
92             ExternalInterface.call("wheelToFlash",false);
93         }
94         private function wheelToFlash(target:DisplayObjectContainer):void
95         {
96
97         }
98     }
99 }
时间: 2024-08-30 12:16:09

[ActionScript] AS3解决html与flash鼠标滚轮冲突的问题的相关文章

Actionscript,AS3,MXML,Flex,Flex Builder,Flash Builder,Flash,AIR,Flash Player之关系

转自zrong's blog:http://zengrong.net/post/1295.htm ActionScript ActionScript通常简称为AS,它是Flash平台的语言.AS编写的程序,最终可以编译成SWF.SWC.SWF就是我们常说的Flash动画.但是现在SWF已经不仅仅是动画,而是RIA的载体. ActionScript有3个版本,分别是1.0版(AS1),2.0版(AS2)和3.0版(AS3).只有Flash Player 9及以上播放器才支持AS3编译的SWF.这三

ubuntu下解决鼠标滚轮不能使用的问题

如果你是在VM下安装 Ubuntu,那么必须安装VMware-tools,才能获得更好的体验,包括屏幕分辨率.声音.和windows共享剪贴板等等. 点击VMware菜单的-VM-Install VMware Tools 这时,在Ubuntu下会自动加载Linux版的VMware Tools的安装光盘镜像.你会看到虚拟机的桌面上出现了一个名为VMware Tools的光盘图标,并且被自动打开.其中包括VMwareTools-xxx-i386.rpm和VMwareTools- xxx.tar.gz

Flash Actionscript AS3 渐变透明 mask遮罩

把图片变成渐变透明(左图是效果图,右图是原图) var a:Sprite = new Sprite(); a.graphics.beginGradientFill(GradientType.LINEAR, [0xff0000,0xff0000], [1,0.3], [0, 255]); a.graphics.drawRect(0, 0, 240, 225); a.graphics.endFill(); addChild(a); a.rotation = 90; a.x = 226; aaa.ma

关于 WebBrowser调用百度地图API 鼠标滚轮缩放地图级别失灵的解决办法

在桌面程序下 百度地图API的鼠标缩放地图功能可能会失灵无效! 这个原因不是API的问题 小弟试了下在WEB上面是没有问题的 于是考虑可能是WebBrowser的获取焦点问题,于是在主窗体 添加了一个窗体激活事件 如下 //小弟用的是WPF所以是Window_Activated //如果你用的是Winform就是 Form1_Activated(object sender, EventArgs e)事件 private void Window_Activated(object sender, E

鼠标滚轮事件MouseWheel

其实在大多数浏览器(IE6, IE7, IE8, Opera 10+, Safari 5+,Chrome)中,都提供了 "mousewheel" 事件.但杯具的是 Firefox 却不支持此事件,不过庆幸 Firefox  中提供了另外一个等同的事件:"DOMMouseScroll" . OK,我们现在已经知道了不同浏览器之间实现的差别,兼容代码如下: var addEvent = (function () { if (window.addEventListener

Engine中如何实现鼠标滚轮缩放反置?

来自:http://zhihu.esrichina.com.cn/?/question/6666 [解决办法]:1,禁用IMapControl的默认鼠标滚轮事件.即设置IMapControl4.AutoMouseWheel= false:2,重写鼠标滚轮事件.比如在Form1_Load函数中加上this.MouseWheel += new System.Windows.Forms.MouseEventHandler(axMapControl1_OnMouseWheel);然后重写private

Winform 中panel的mousewheel鼠标滚轮事件触发

如果将窗体或容器控件(如Panel控件)的AutoScroll属性设置为True时,那么当窗体或Panel容不下其中的子控件时就会出现 滚动条,通过移动滚动条可以上下显示出窗体或Panel中的全部内容.但是默认情况下滚动条的移动只能通过鼠标直接拖动滚动条来实现,而不能通过鼠标的滚 轮来实现上下移动,因此需要手动添加代码来实现这个功能. 滚动鼠标的滚轮,触发的是窗体或控件上的 MouseWheel 事件.但是在VS.net2005中,窗体和控件的事件列表中却不包含 MouseWheel 事件,因此

在unity中用鼠标实现在场景中拖动物体,用鼠标滚轮实现缩放

在场景中添加一个Plan,Camera,Directional Light,Cube.添加两个脚本scrollerScirpt(挂在Camera),CubeDragScript(挂在Cube上). 1.鼠标滚轮实现缩放:将摄像机的镜头拉近或者拉远,调整摄像机的视角就可以实现,主要实现代码如下: void Update () { //鼠标滚轮的效果 //Camera.main.fieldOfView 摄像机的视野 //Camera.main.orthographicSize 摄像机的正交投影 //

如何让VB6代码编辑器垂直滚动条随鼠标滚轮滚动

VB6毕竟是很老的产品了,它的代码编辑器垂直滚动条并不能随鼠标的滚轮而滚动,这个问题会让我们在编写代码的时候觉得很不方便,不过还是有一种方法可以解决这个问题的.    先下载一个微软发布的"VB6IDEMouseWheelAddin.dll"文件(此文件已经上传到百度网盘,网址:http://pan.baidu.com/s/1c06KY7e,或者也可以自己百度一下该文件名下载),然后按照以下的方法进行(注意:此处介绍的是一种通用的方法,适合是32位和64位的系统上使用): 一.  将下