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 文件状态正常,准备打 ...
随机推荐
- 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago
# #错误日志 2016-11-10 16:19:20,834 ERROR [org.quartz.core.JobRunShell] - Job DEFAULT.jobtask threw an u ...
- hdu 3478 Catch(染色 dfs 或 bfs )
Problem Description A thief is running away! We can consider the city to N–. The tricky thief starts ...
- 从Android Handler内部类到WeakReference的知识关联
Handler: 普通使用方法: Handler用于处理和从队列MessageQueue中得到Message.一般我们要重写Handler的handleMessage(Message msg){}方法 ...
- Hadoop: Start-all.sh 后发现JPS后Namenode没有启动
重新格式化Namenode:hadoop namenode -format 然后启动hadoop:start-all.sh 执行下JPS命令就可以看到NameNode了
- 查看Android数据库文件
使用Eclipse DDMS的File Explorer不能能看到Data目录下面的东西,可能由下面原因引起的 手机没有Root -- 可以使用Root大师 Data文件权限不够 -- 可以使用Ro ...
- CentOS 7 U盘安装解决找不到U盘问题
在使用U盘进入CentOS7系统安装选项时,按下Tab键,在屏幕下方出现:vmlinuz initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x ...
- windows8开发学习笔记
XAML行列定义 <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> &l ...
- 容器vector的使用总结 容器stack(栈)
0.头文件:#include<vector>; using namespace std; 1.定义: vector<type> vec; 2.迭代器 vector<typ ...
- AJAX防重复提交的办法总结
最近的维护公司的一个代理商平台的时候,客服人员一直反映说的统计信息的时候有重复数据,平台一直都很正常,这个功能是最近新进的一个实习生同事写的功能,然后就排查问题人所在,发现新的这个模块的AJAX提交数 ...
- php 数组 array_intersect_key() array_unique()移除重复
<?php // array_unique($array) 去除重复 // array_unshif()向数组的顶部追加函数 // array_shif($a,"ss")向数 ...