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. nginx配置 的话注意几点 1.错误时注意看log 2.天威证书的话,有文档按照其文档一步步配置即可;3每句话的结尾注意千万别丢掉分号

    nginx配置 的话注意几点 1.错误时注意看log  2.天威证书的话,有文档按照其文档一步步配置即可:3每句话的结尾注意千万别丢掉分号:4.配置https时 其转发可以转发到http上 pass_ ...

  2. [Spring boot] web应用返回jsp页面

    同事创建了一个spring boot项目,上传到svn.需要我来写个页面.下载下来后,始终无法实现在Controller方法中配置直接返回jsp页面. 郁闷了一下午,终于搞定了问题.在此记录一下. 目 ...

  3. php 中利用json_encode和json_decode传递包括特殊字符的数据

    </pre><span style="font-size:24px"></span><pre name="code" ...

  4. 面向对象3-this的用法

    1.当有定时器时 this会指向window <script type="text/javascript"> function Aaa(){ var _this=thi ...

  5. android 根据网络来获取外网ip地址及国家,地区的接口

    新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪多地域测试方法:http://int.dpool. ...

  6. Asp.Net使用Bulk批量插入数据

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Di ...

  7. iOS9基础知识(OC)笔记

    1月16日 Objective  C(20世纪80年代初) 一.OC语言概述 1.1985年,Steve  Jobs成立了NeXT公司 2.1996年,12月20日,苹果公司宣布收购了NeXT  ...

  8. 3D模型制作

    agisoft: http://www.agisoft.com/downloads/installer/ http://pan.baidu.com/s/1dDwA3tf http://pan.baid ...

  9. 从汇编看c++成员函数指针(三)

    前面的从汇编看c++中成员函数指针(一)和从汇编看c++成员函数指针(二)讨论的要么是单一类,要么是普通的多重继承,没有讨论虚拟继承,下面就来看一看,当引入虚拟继承之后,成员函数指针会有什么变化. 下 ...

  10. HDU1043 Eight(BFS)

    Eight(South Central USA 1998) Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...