Flash AS3教程:Level2D类
2008-06-05 11:21:58 来源:WEB开发网Level2D源代码:
CODE:
package index.com.truss{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.events.Event;
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
import index.com.events.Level2DEvent;
public class Level2D implements IEventDispatcher{
private var dispatcher:EventDispatcher;
private var _range:DisplayObjectContainer;
public function Level2D(range_:DisplayObjectContainer){
dispatcher = new EventDispatcher(this);
_range = range_;
}
//重排
public function reset():Array{
var tmpAr:Array = getDisplay();
var getYAr:Array = getDisplay("y");
var addYAr:Array = getYAr.concat().sort(16);
if(getYAr.toString() != addYAr.toString()){
inOrder(tmpAr.sortOn("y",16));
//发布层级改变事件
dispatcher.dispatchEvent(new Level2DEvent(Level2DEvent.LEVEL_RESET));
}
getYAr = addYAr = null;
return tmpAr;
}
//返回当前范围所有对象
public function getDisplay(arg:Object = null):Array{
var i:int;
var tmpAr:Array = new Array;
var num:int = _range.numChildren;
if(arg == null){
for(i = 0; i < num; i ++) tmpAr.push(_range.getChildAt(i));
}else if(arg is String){
for(i = 0; i < num; i ++) tmpAr.push(_range.getChildAt(i)[arg]);
}else{
for(i = 0; i < num; i ++){
var dis:DisplayObject = _range.getChildAt(i);
var isEnter:Boolean = true;
for(var index:String in arg){
if(dis[index] != arg[index]){
isEnter = false;
break;
}
}
if(isEnter) tmpAr.push(dis);
dis = null;
}
}
return tmpAr;
}
//以特定方式遍历该范围的显示对象
public function forEach(fun:Function,arg:Object = null):void{
var tmpAr:Array = getDisplay(arg);
for(var i:int = 0; i < tmpAr.length; i ++){
var str:String = fun(tmpAr[i],i);
if(str == "true") return;
}
tmpAr = null;
}
//给定一个排序数组,进行排序
protected function inOrder(tmpAr:Array):void{
for(var i:int = 0; i < tmpAr.length; i ++) _range.addChild(tmpAr[i] as DisplayObject);
}
//设置实时重排
public function set isTime(_isTime:Boolean):void{
if(_isTime) _range.addEventListener(Event.ENTER_FRAME,resetFun);
else _range.removeEventListener(Event.ENTER_FRAME,resetFun);
}
//实时重排
private function resetFun(e:Event):void{
reset();
}
//返回操作区域
public function get range():DisplayObjectContainer{
return _range;
}
//侦听
public function addEventListener(type:String,listener:Function,useCapture:Boolean = false,priority:int = 0,useWeakReference:Boolean = false):void{
dispatcher.addEventListener(type,listener,useCapture,priority,useWeakReference);
}
//调度
public function dispatchEvent(event:Event):Boolean{
return dispatcher.dispatchEvent(event);
}
//是否含有侦听
public function hasEventListener(type:String):Boolean{
return dispatcher.hasEventListener(type);
}
//移除侦听
public function removeEventListener(type:String,listener:Function,useCapture:Boolean = false):void{
dispatcher.removeEventListener(type,listener,useCapture);
}
//检查侦听
public function willTrigger(type:String):Boolean{
return dispatcher.willTrigger(type);
}
}
}
Level2DEvent类源代码:
CODE:
package index.com.events{
import flash.events.Event;
public class Level2DEvent extends Event{
public static const LEVEL_RESET:String = "levelReset";
public function Level2DEvent(type:String){
super(type);
}
}
}
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
- ››asp获取毫秒数
- ››asp.net报“INSERT INTO 语句的语法错误解决
更多精彩
赞助商链接