[AS3] 动画与程序结合 ENTER_FRAME 取代addFrameScript

package {
    import flash.display.FrameLabel;
    import flash.events.Event;
    public class 帧执行类 {
        public var 对象;
        public var 结束方法:Function;
        private var 结束帧:Number;
        private var 循环执行:Boolean;
        public function 帧执行类(MC) {
            对象=MC;
        }
        public function 赋于方法(帧数,_结束方法=null,_循环执行=false) {
            //检测传来的帧数是否是标签
            if (isNaN(Number(帧数))) {
                //传来的是标签
                var 标签组:Array = 对象.currentLabels;
                for (var i:uint = 0; i < 标签组.length; i++) {
                    var 标签:FrameLabel = 标签组[i];
                    //trace("frame " + label.frame + ": " + label.name);
                    if (标签.name==帧数) {
                        //return label.frame
                        帧数=标签.frame;
                        break;
                    }
                }
            }
            结束帧=帧数;
            循环执行=_循环执行;
            结束方法=_结束方法
            //
            对象.addEventListener(Event.ENTER_FRAME, 实时检测);
        }
        private function 实时检测(Evt:Event) {            
            if (Evt.target.currentFrame==结束帧) {
                if (!循环执行) {
                    Evt.currentTarget.removeEventListener(Event.ENTER_FRAME, 实时检测);
                }
                //trace("执行");
                if(结束方法!=null){
                    结束方法(Evt.target,结束帧)
                }
            }
        }
    }
}
//
//
//==============源码下载============
下载文件 点击下载此文件

//=====================================
//
//转载请注明出处:羽柴 鬼铃-blog  
//     www.ycflash.com/
//=====================================

posted on 2012-02-22 13:58  格雷普琳斯  阅读(186)  评论(0编辑  收藏  举报

导航