Node3D
forked from 円と線 (diff: 51)
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/c1iT
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.*;
import flash.ui.*;
import net.hires.debug.Stats;
[SWF(width=465,height=465,backgroundColor=0x0,frameRate=120)]
public class FlashTest extends Sprite
{
public const DEPTH:Number = new Number( 1000 );
public var sw:Number=stage.stageWidth;
public var sh:Number=stage.stageHeight;
public var myArray:Array = new Array();
public var max:Number=2;
public var _line:Sprite;
public var _node:Sprite;
public function FlashTest()
{
_line = new Sprite();
for (var n:Number=0; n<max; n++)
{
_node = new Sprite();
with (_node.graphics)
{
beginFill(0x999999,1);
drawCircle(0,0,20);
endFill();
}
_node.x = Math.random()*sw;
_node.y = Math.random()*sh;
_node.z = Math.random()*DEPTH;
addChild(_node);
myArray.push(_node);
myArray[n].addEventListener(MouseEvent.MOUSE_DOWN,xDown);
}
stage.addEventListener(Event.ENTER_FRAME,xEnter);
function xEnter(e:Event):void
{
_line.graphics.clear();
for (var nn:Number =0; nn<max; nn++) {
if (nn==max-1) {
with (_line.graphics) {
lineStyle(3,0xCCCCCC,1);
moveTo(myArray[nn].x,myArray[nn].y);
lineTo(myArray[0].x,myArray[0].y);
}
} else {
with (_line.graphics)
{
lineStyle(3,0xCCCCCC,1);
moveTo(myArray[nn].x,myArray[nn].y);
lineTo(myArray[nn + 1].x,myArray[nn + 1].y);
}
}
addChild(_line);
}
}
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..
}
}
}