flash 原生UI 与 starling 鼠标事件冲突解决办法

来源:互联网 发布:阿里云免费云主机 编辑:程序博客网 时间:2024/05/18 01:07

package com.util.core.commands{import com.game.ui.main.WindowState;import flash.display.Stage;import flash.events.MouseEvent;/** * 作用于判断是否点击到原生的FLASH UI 界面 如果是的话就不向starling 发送 点击事件 如果不是的话则继续发送事件 * @author Administrator *  */public class StarlingEventShield{public function StarlingEventShield(){}static public var mouseDown:Boolean = false; static public var mouseDrag:Boolean = false; static private var stage:Stage;static public function activate( stage:Stage ) : void{if ( StarlingEventShield.stage ) return; StarlingEventShield.stage = stage;stage.addEventListener( MouseEvent.MOUSE_DOWN, onStage_MouseDown, false, 1, true );stage.addEventListener( MouseEvent.MOUSE_UP, onStage_MouseUp, false, 1, true );}static private function onStage_MouseDown(e:MouseEvent):void{if(WindowState.windows == WindowState.MFightWindow){if(e.target == MClient.client){mouseDown = true;}elseif ( e.target != stage ) e.stopImmediatePropagation();else mouseDown = true; }}static private function onStage_MouseMove(e:MouseEvent):void{if ( mouseDown ) mouseDrag = true;if ( e.target != stage && !mouseDrag ) e.stopImmediatePropagation();}static private function onStage_MouseUp(e:MouseEvent):void{if(WindowState.windows == WindowState.MFightWindow){if ( e.target != stage && !mouseDrag ) e.stopImmediatePropagation();mouseDown = mouseDrag = false;}}static public function deactivate() : void{if ( !stage ) return;stage.removeEventListener( MouseEvent.MOUSE_DOWN, onStage_MouseDown );stage.removeEventListener( MouseEvent.MOUSE_UP, onStage_MouseUp );mouseDown = mouseDrag = false;stage = null;}}}

在项目中出现过当前问题本来以为在程序里面用事件截断处理就可以不会出现事件渗透到starling,而且在pc上是可以实现当前的目标。

但是

真正在移动设备上使用的时候就不是那么简单的了。事件还是能够被starling监控到。咋办呢--直接上源码吧 这也是在一个外文的网站上看到的一个代码哪个网址不记得了不好意思。

希望能够帮助到其他人吧。

0 0
原创粉丝点击