forked from: 円と線

by bradsedito forked from 円と線 (diff: 6)
♥0 | Line 61 | Modified 2011-09-01 14:56:46 | MIT License
play

ActionScript3 source code

/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bmrb
 */

// forked from yuugurenote's 円と線
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;    
    
     [SWF(width=465,height=465,backgroundColor=0x0,frameRate=60)]
    
    public class FlashTest extends Sprite {
        public var sw:Number=stage.stageWidth;
        public var sh:Number=stage.stageHeight;
        public var myArray:Array = new Array();
        public var max:Number=4;
        var myLine:Sprite =new Sprite();
     
        
        public function FlashTest() {
            for (var n:Number=0; n<max; n++) {
    var myCircle:Sprite = new Sprite();
    with (myCircle.graphics) {
        beginFill(0x999999,1);
        drawCircle(0,0,5);
        endFill();
    }
    myCircle.x=Math.random()*sw;
    myCircle.y=Math.random()*sh;
    addChild(myCircle);
    myArray.push(myCircle);
    myArray[n].addEventListener(MouseEvent.MOUSE_DOWN,xDown);
}

stage.addEventListener(Event.ENTER_FRAME,xEnter);
function xEnter(e:Event):void {
    myLine.graphics.clear();
    for (var nn:Number =0; nn<max; nn++) {
        if (nn==max-1) {
            with (myLine.graphics) {
                lineStyle(1,0xCCCCCC,1);
                moveTo(myArray[nn].x,myArray[nn].y);
                lineTo(myArray[0].x,myArray[0].y);
            }
        } else {
            with (myLine.graphics) {
                lineStyle(1,0xCCCCCC,1);
                moveTo(myArray[nn].x,myArray[nn].y);
                lineTo(myArray[nn + 1].x,myArray[nn + 1].y);
            }
        }
        addChild(myLine);
    }
}

function xDown(e:MouseEvent):void {
    e.target.startDrag();
    e.target.addEventListener(MouseEvent.MOUSE_MOVE, xMove);
    stage.addEventListener(MouseEvent.MOUSE_UP, xUp);
}
function xMove(e:MouseEvent):void {
    e.updateAfterEvent();
}
function xUp(e:MouseEvent):void {
    e.target.stopDrag();
    e.target.removeEventListener(MouseEvent.MOUSE_MOVE, xMove);
    stage.removeEventListener(MouseEvent.MOUSE_UP, xUp);
}
            // write as3 code here..
            
        }
    }
}