WEB开发网
开发学院图形图像Flash Flash as3教程:OutDisplay类 阅读

Flash as3教程:OutDisplay类

 2008-06-05 11:22:09 来源:WEB开发网   
核心提示: 类的源代码: CODE:package index.base.func{import flash.display.DisplayObject;import flash.display.DisplayObjectContainer;import flash.events.Event;impo

类的源代码:

CODE:

package index.base.func{
    
    import flash.display.DisplayObject;
    import flash.display.DisplayObjectContainer;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    
    public class OutDisplay extends EventDispatcher{
        
        //保存所有对象
        private var objAr:Array;
        //保存侦听类型
        private var type:String;
        //保存侦听范围
        private var dis:DisplayObject;
        
        //构造函数
        public function OutDisplay(_type:String,_dis:DisplayObject,...objs){
            type = _type;
            objAr = objs;
            dis = _dis;
            dis.addEventListener(_type,fun);
        }
        
        //事件处理
        private function fun(e:Event):void{
            for(var i:uint = 0;i<objAr.length;i++){
                if(e.target == objAr[i]) return;
                if(objAr[i] is DisplayObjectContainer){
                    if(objAr[i].contains(e.target)) return;
                }
            }
            dis.removeEventListener(type,fun);
            dispatchEvent(new Event(Event.CANCEL));
        }
        
        //添加对象
        public function add(...objs):Array{
            for(var i:int = 0; i < objs.length; i ++){
                objAr.push(objs[i]);
            }
            return objects;
        }
        
        //获取对象列表
        public function get objects():Array{
            return objAr;
        }
        
        //卸载
        public function clear(isDispatch:Boolean = false):void{
            if(isDispatch) dispatchEvent(new Event(Event.CANCEL));
            dis.removeEventListener(type,fun);
            objAr = null;
        }
        
    }
}

上一页  1 2 

Tags:Flash as 教程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接