as3 页游中,新手指导中,屏蔽所有交互对象,但除了指定交互对象可用的方法【转http://blog.csdn.net/linjf520/article/details/9450945】
package
{
import flash.display.InteractiveObject;
import flash.display.Stage;
import flash.events.MouseEvent; /**
* 新手指导管理器
* @author jave.lin
* @date 2013-7-24
*/
public class GuideManager{ private static var stage:Stage; /**设置舞台*/
public static function setStage(stage:Stage):void{
GuideManager.stage = stage;
}
/**锁定全局*/
public static function lockAll():void{
if(!stage) throw new Error("GuideManager未设置stage");
stage.addEventListener(MouseEvent.CLICK, onLockAll, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onLockAll, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_UP, onLockAll, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onLockAll, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_OVER, onLockAll, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_OUT, onLockAll, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, onLockAll, true, int.MAX_VALUE);
}
/**解除锁定全局*/
public static function unLockAll():void{
stage.removeEventListener(MouseEvent.CLICK, onLockAll, true);
stage.removeEventListener(MouseEvent.MOUSE_DOWN, onLockAll, true);
stage.removeEventListener(MouseEvent.MOUSE_UP, onLockAll, true);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onLockAll, true);
stage.removeEventListener(MouseEvent.MOUSE_OVER, onLockAll, true);
stage.removeEventListener(MouseEvent.MOUSE_OUT, onLockAll, true);
stage.removeEventListener(MouseEvent.MOUSE_WHEEL, onLockAll, true);
} private static function onLockAll(e:MouseEvent):void{
e.preventDefault();
e.stopImmediatePropagation();
e.stopPropagation();
} /**当前激活,可以控制的对象*/
public static var curActivedObj:InteractiveObject; /**
* 屏蔽掉所有鼠标操作,但除了指定的obj交互对象
* (如果需要屏蔽键盘操作也但样加上对所有键盘事件的处理)
* */
public static function lockAllButThisOne(obj:InteractiveObject):void{
unLock();
curActivedObj = obj;
stage.addEventListener(MouseEvent.CLICK, checkEvent, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_DOWN, checkEvent, true, int.MAX_VALUE);
stagej.addEventListener(MouseEvent.MOUSE_UP, checkEvent, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_MOVE, checkEvent, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_OVER, checkEvent, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_OUT, checkEvent, true, int.MAX_VALUE);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, checkEvent, true, int.MAX_VALUE);
} /**解除屏蔽*/
public static function unLock():void{
if(stage){
stage.removeEventListener(MouseEvent.CLICK, checkEvent, true);
stage.removeEventListener(MouseEvent.MOUSE_DOWN, checkEvent, true);
stage.removeEventListener(MouseEvent.MOUSE_UP, checkEvent, true);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, checkEvent, true);
stage.removeEventListener(MouseEvent.MOUSE_OVER, checkEvent, true);
stage.removeEventListener(MouseEvent.MOUSE_OUT, checkEvent, true);
stage.removeEventListener(MouseEvent.MOUSE_WHEEL, checkEvent, true);
}
} /**检查、滤过交互对象的事件*/
private static function checkEvent(e:MouseEvent):void{
if(e.target != curActivedObj){//所有鼠标触发的事件都屏蔽
e.preventDefault();
e.stopImmediatePropagation();
e.stopPropagation();
}
}
}
}
import flash.display.Sprite; class Main extends Sprite{ private var btnVec:Vector.<Sprite>; public function Main(){
btnVec = new Vector.<Sprite>();
for (var i:int = 0; i < 10; i++){
var btn:Sprite = getBtn();
btn.x = 100;
btn.y = 100 + (30 * i);
addChild(btn);
}
//这里我只想第5个按钮可用,其它都不可用即可
GuideManager.setStage(stage);//这里只需要在游戏初始化时setStage一次即可
GuideManager.lockAllButThisOne(btnVec[4]);
// //解除屏蔽
// GuideManager.unLock();
} private function getBtn():Sprite{
var result:Sprite = new Sprite();
result.graphics.beginFill(uint(Math.random() * uint.MAX_VALUE));
result.graphics.drawRect(0, 0, 100, 30);
result.graphics.endFill();
return result;
}
}
as3 页游中,新手指导中,屏蔽所有交互对象,但除了指定交互对象可用的方法【转http://blog.csdn.net/linjf520/article/details/9450945】的更多相关文章
- 快速掌握 Android Studio 中 Gradle 的使用方法 [转http://blog.csdn.net/feelang/article/details/41783317]
Gradle是可以用于Android开发的新一代的 Build System, 也是 Android Studio默认的build工具. Gradle脚本是基于一种JVM语言 -- Groovy,再加 ...
- 数组中&a与&a[0]的区别 转载自http://blog.csdn.net/FX677588/article/details/74857473
在探讨这个问题之前,我们首先来看一道笔试题,如下: [摘自牛客网]下列代码的结果是:(正确答案是 C) main() { int a[5]={1,2,3,4,5}; int *ptr=(int *)( ...
- 浏览器中的data类型的Url格式,data:image/png,data:image/jpeg!(源自:http://blog.csdn.net/roadmore/article/details/38498719)
所谓"data"类型的Url格式,是在RFC2397中 提出的,目的对于一些“小”的数据,可以在网页中直接嵌入,而不是从外部文件载入.例如对于img这个Tag,哪怕这个图片非常非常 ...
- 向txt文件中写入内容(覆盖重写与在末尾续写+FileOutputStream与FileWriter)(转发:https://blog.csdn.net/bestcxx/article/details/51381460)
!!!! 读取txt文件中的内容 import java.io.BufferedReader; import java.io.File; import java.io.FileReader; /** ...
- 虚拟机中的CentOS7如何上网?---https://blog.csdn.net/nothing2017/article/details/61420767
虚拟机中的CentOS7如何上网?https://blog.csdn.net/nothing2017/article/details/61420767
- (转载)RTMP协议中的AMF数据 http://blog.csdn.net/yeyumin89/article/details/7932585
为梦飞翔 (转载)RTMP协议中的AMF数据 http://blog.csdn.net/yeyumin89/article/details/7932585 这里有一个连接,amf0和amf3的库, ...
- R语言中的正则表达式(转载:http://blog.csdn.net/duqi_yc/article/details/9817243)
转载:http://blog.csdn.net/duqi_yc/article/details/9817243 目录 Table of Contents 1 正则表达式简介 2 字符数统计和字符翻译 ...
- 转-spring-boot 注解配置mybatis+druid(新手上路)-http://blog.csdn.net/sinat_36203615/article/details/53759935
spring-boot 注解配置mybatis+druid(新手上路) 转载 2016年12月20日 10:17:17 标签: sprinb-boot / mybatis / druid 10475 ...
- 通信中的错误代码 (repost from https://blog.csdn.net/zzhuan_1/article/details/80066716)
• 100 - 继续.• 101 - 切换协议.• 110 重新启动标记答复.• 120 服务已就绪,在 nnn 分钟后开始.• 125 数据连接已打开,正在开始传输.• 150 文件状态正常,准备打 ...
随机推荐
- LightOJ 1338 && 1387 - Setu && LightOJ 1433 && CodeForces 246B(水题)
B - B Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status P ...
- swift中通知的使用
1.发通知.(以这条通知为例,通知名字:gameOverNotification.通知参数:title) NSNotificationCenter.defaultCenter().postNotifi ...
- iOS蓝牙4.0开发例子
1建立中心角色 1 2 3 #import <CoreBluetooth/CoreBluetooth.h> CBCentralManager *manager; manager = [ ...
- 冒泡排序 选择排序 插入排序希尔排序 java
双向冒泡 package com.huang; public class _014_bubb_sort { int[] b={1,2}; static int a[]={12,4,35,65,43,6 ...
- JSP 实现 之 读取数据库显示图片
用JSP从数据库中读取图片并显示在网页上 环境mysql+tomcat: <1>先在mysql下建立如下的table. 并insert图像. mysql.sql文件如下: ) unsign ...
- node.js入门(三)调式
1.安装调式工具 打开命令行工具,输入以下内容,然后回车. npm install -g node-inspector 等待安装成功呢后,我们就可以使用 node-debug 文件名 这个命令来调式我 ...
- C# 添加服务引用。
1,服务引用给的实例(需要一个网址连接) http://192.168.17.131:12170/amtiot.gis.WCF/SpatialAnalysis.svc (类似于这样的一个网址) 在网 ...
- linux网络编程:三次握手与四次挥手
建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 其中三次握手即建立连接 四次挥手则为关闭连接 TCP连接的11种状态 客户端独有的:(1)SYN_SENT (2)FIN ...
- C#导出Word文档开源组件DocX
1.帮助文档,这东西找了很久,而且它版本很旧,还是英文,W8.1系统上打不开 http://download.csdn.net/detail/zuofangyouyuan/7673573 2.开源网址 ...
- ubuntu中vim找不到配色方案blackboard
在ubuntu下启动vim,提示找不到配色方案blackboard(或其他的), 如何挑选自己喜欢的配色方案呢?在/usr/share/vim/vim72/colors中,(这里根据自己的vim版本选 ...