Dragging MovieClips

View Code
package {

    import flash.display.MovieClip;

    import flash.display.Sprite;

    import flash.events.MouseEvent;

    import flash.events.ThrottleEvent;

    import flash.geom.Rectangle;    

    

    public class Test extends Sprite {

        private var myMC:MovieClip;

        public function Test() {

            myMC = new MovieClip();

            myMC.graphics.beginFill(0xff00ff);

            myMC.graphics.drawRect(0, 0, 50, 50);

            myMC.graphics.endFill();

            addChild(myMC);

            myMC.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

            myMC.addEventListener(MouseEvent.MOUSE_UP, mouseReleasedHandler);

        }

        private function mouseDownHandler(e:MouseEvent):void {            

            myMC.startDrag(,);

            stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

        }

        private function mouseReleasedHandler(e:MouseEvent):void {

            myMC.stopDrag();

            stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

        }

        private function mouseMoveHandler(e:MouseEvent):void {

            e.updateAfterEvent();            

        }

    }

}

 

你可能感兴趣的:(drag)