In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

ドラッグする

Get Adobe Flash player
by 9re 16 Dec 2009
/**
 * Copyright 9re ( http://wonderfl.net/user/9re )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/sS7A
 */

package{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    public class MouseDrag extends Sprite { 
        public function MouseDrag(){
            var circle:Sprite = new Sprite();
            //円を描く
            circle.graphics.beginFill(0x333333);
            circle.graphics.drawCircle(0,0,20);
            circle.graphics.endFill();

            //手のカーソルに変更
            circle.buttonMode = true;

            //位置の調節
            circle.x=232;
            circle.y=232;

            //表示リストに追加
            addChild(circle);

            circle.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
            circle.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
        }

        //マウス・ダウン時にドラッグ開始
        private function onMouseDown(e:MouseEvent):void
        {
            e.currentTarget.startDrag();
        }

        //マウス・アップ時にドラッグ終了
        private function onMouseUp(e:MouseEvent):void
        {
            e.currentTarget.stopDrag();
        }
    }
}