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】的更多相关文章

  1. 快速掌握 Android Studio 中 Gradle 的使用方法 [转http://blog.csdn.net/feelang/article/details/41783317]

    Gradle是可以用于Android开发的新一代的 Build System, 也是 Android Studio默认的build工具. Gradle脚本是基于一种JVM语言 -- Groovy,再加 ...

  2. 数组中&a与&a[0]的区别 转载自http://blog.csdn.net/FX677588/article/details/74857473

    在探讨这个问题之前,我们首先来看一道笔试题,如下: [摘自牛客网]下列代码的结果是:(正确答案是 C) main() { int a[5]={1,2,3,4,5}; int *ptr=(int *)( ...

  3. 浏览器中的data类型的Url格式,data:image/png,data:image/jpeg!(源自:http://blog.csdn.net/roadmore/article/details/38498719)

    所谓"data"类型的Url格式,是在RFC2397中 提出的,目的对于一些“小”的数据,可以在网页中直接嵌入,而不是从外部文件载入.例如对于img这个Tag,哪怕这个图片非常非常 ...

  4. 向txt文件中写入内容(覆盖重写与在末尾续写+FileOutputStream与FileWriter)(转发:https://blog.csdn.net/bestcxx/article/details/51381460)

    !!!! 读取txt文件中的内容 import java.io.BufferedReader; import java.io.File; import java.io.FileReader; /** ...

  5. 虚拟机中的CentOS7如何上网?---https://blog.csdn.net/nothing2017/article/details/61420767

    虚拟机中的CentOS7如何上网?https://blog.csdn.net/nothing2017/article/details/61420767

  6. (转载)RTMP协议中的AMF数据 http://blog.csdn.net/yeyumin89/article/details/7932585

    为梦飞翔   (转载)RTMP协议中的AMF数据 http://blog.csdn.net/yeyumin89/article/details/7932585 这里有一个连接,amf0和amf3的库, ...

  7. R语言中的正则表达式(转载:http://blog.csdn.net/duqi_yc/article/details/9817243)

    转载:http://blog.csdn.net/duqi_yc/article/details/9817243 目录 Table of Contents 1 正则表达式简介 2 字符数统计和字符翻译 ...

  8. 转-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 ...

  9. 通信中的错误代码 (repost from https://blog.csdn.net/zzhuan_1/article/details/80066716)

    • 100 - 继续.• 101 - 切换协议.• 110 重新启动标记答复.• 120 服务已就绪,在 nnn 分钟后开始.• 125 数据连接已打开,正在开始传输.• 150 文件状态正常,准备打 ...

随机推荐

  1. Unsupported Media Type 415问题解决办法(Ajax)

    场景:Ajax传一个json对象到服务器,让参数自动封装至与json对象匹配的java对象中. 错误类型 错误类型1: "status":415 "error" ...

  2. IOS 打印网络请求全链接

    NSMutableString *urlStr = [NSMutableString stringWithFormat:@"%@?",request.URL]; ;i<[pa ...

  3. ios常用的几个动画代码

      #import "MianViewController.h" #import <QuartzCore/QuartzCore.h> @interface MianVi ...

  4. STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)(转)

    向量(vector) <vector> 连续存储的元素<vector> Vector<int>c; c.back()    传回最后一个数据,不检查这个数据是否存在 ...

  5. 【十】注入框架RoboGuice使用:(Your First Testcase)

    上一篇我们简单的介绍了一下RoboGuice的使用([九]注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)),今天 ...

  6. H5单页面架构:自定义路由 + requirejs + zepto + underscore

    angular优点: 强大的数据双向绑定 View界面层组件化 内置的强大服务(例如表单校验) 路由简单 angular缺点: 引入的js较大,对移动端来说有点吃不消 语法复杂,学习成本高 backb ...

  7. php错误日志级别

    ; E_ALL             所有错误和警告(除E_STRICT外) ; E_ERROR           致命的错误.脚本的执行被暂停. ; E_RECOVERABLE_ERROR   ...

  8. winform —— listview创建表及简单的增删改查

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. git push -u origin master 上传出错问题

    ============================================ 跟着廖学锋教程初学git发现个很奇怪的问题,后面原来发现是这样,有点逗.. ================= ...

  10. Letter of inquiry about employment possibilities, e-mail version

    Subject: (logical to recipient!) Inquiry about software engineering position after completion of M.S ...