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. mongoDb c driver

    1,yum dependencies Centos,RHEL Fedora: $ sudo yum install git gcc automake autoconf libtool Debian: ...

  2. 为 Python Server Pages 和 Oracle 构建快速 Web 开发环境。

    为 Python Server Pages 和 Oracle 构建快速 Web 开发环境. - 在水一方 - 博客频道 - CSDN.NET 为 Python Server Pages 和 Oracl ...

  3. Ajax下载文件(页面无刷新)

    说明:Ajax是无法实现文件传输的,本文只是模拟了Ajax不刷新页面就可以请求并返回数据的效果.实质上还是通过提交form表单来返回文件流的输出. 分步实现逻辑: ajax请求服务器,访问数据库,根据 ...

  4. Comet学习资料

    什么是Comet: http://baike.baidu.com/view/577938.htm?fr=ala0_1 Comet介绍: http://www.ibm.com/developerwork ...

  5. Ice_cream's world I

    Ice_cream's world I Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  6. [工作问题总结]MyEclipse 注册

    ------------------------------ASP.Net+Android+IO开发 .Net培训 期待与您交流!------------------------------ 1.本人 ...

  7. C++类静态成员变量和const常量的初始化方法

    C++类静态成员变量和const常量在定义类的时候就必须初始化,否则都会编译出错. 而具初始化方法为: C++类静态成员变量初始化方法 #include <iostream> #inclu ...

  8. Codeforces 474D Flowers dp(水

    题目链接:点击打开链接 思路: 给定T k表示T组測试数据 每组case [l,r] 有2种物品a b.b物品必须k个连续出现 问摆成一排后物品长度在[l,r]之间的方法数 思路: dp[i] = d ...

  9. [Redux] Generating Containers with connect() from React Redux (AddTodo)

    Code to be refacted: const AddTodo = (props, { store }) => { let input; return ( <div> < ...

  10. Swift继承的用法

    一个类可以继承另一个类的方法,属性和其它特性.当一个类继承其它类,继承类叫子类,被继承类叫超类(或父类).在Swift中,继承是区分「类」与其它类型的一个基本特征. 在Swift中,类可以调用和访问超 ...