其他分享
首页 > 其他分享> > as3.0 拖动条

as3.0 拖动条

作者:互联网

package com{
    import flash.display.MovieClip;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;

    public class DragMusic extends MovieClip {

        private var dragMc:MovieClip;
        private var lineMc:MovieClip;
        private var progressMc:MovieClip;
        private var moveMc:MovieClip;
        private var timer:Timer=new Timer(25);
        private var thisMc:MovieClip;
        private var rec:Rectangle;
        public function DragMusic(_dragMc:MovieClip,_lineMc:MovieClip,_progressMc:MovieClip,_moveMc:MovieClip) {
            lineMc=_lineMc;
            dragMc=_dragMc;
            moveMc=_moveMc;
            progressMc=_progressMc;

            progressMc.mouseChildren=false;
            progressMc.mouseEnabled=false;

            thisMc=dragMc.parent as MovieClip;
            lineMc.addEventListener(MouseEvent.MOUSE_DOWN,onLine);
            dragMc.addEventListener(MouseEvent.MOUSE_DOWN,onDrag);

            timer.addEventListener(TimerEvent.TIMER,onTimer);
            timer.start();

            rec=new Rectangle(lineMc.x,lineMc.y,lineMc.width,0);
        }
        private function onDrag(e:MouseEvent) {
            if (e.type=="mouseDown") {
                thisMc.stage.addEventListener(MouseEvent.MOUSE_UP,onDrag);
                thisMc.stage.addEventListener(MouseEvent.MOUSE_MOVE,onDrag);
                dragMc.startDrag(false,rec);
                moveMc.stop();
                timer.stop();
            } else if (e.type=="mouseMove") {
                moveFun()
            } else if (e.type=="mouseUp") {
                thisMc.stage.removeEventListener(MouseEvent.MOUSE_UP,onDrag);
                thisMc.stage.removeEventListener(MouseEvent.MOUSE_MOVE,onDrag);
                stopDrag();
                timer.start();
                moveMc.play();
            }
        }
        private function onLine(e:MouseEvent) {
            var clickNum:Number=mouseX;
            dragMc.x=clickNum;
            moveFun()
        }
        private function onTimer(e:TimerEvent) {
            dragMc.x=(moveMc.currentFrame*lineMc.width)/moveMc.totalFrames+lineMc.x;
            progressMc.width=dragMc.x-lineMc.x;
        }

        private function moveFun() {
            moveMc.gotoAndPlay(int((dragMc.x-lineMc.x)*moveMc.totalFrames/lineMc.width));
            progressMc.width=dragMc.x-lineMc.x;
        }

    }
}

 

标签:as3.0,lineMc,moveMc,拖动,MouseEvent,private,dragMc,MovieClip
来源: https://www.cnblogs.com/zqiang0803/p/10955476.html