/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/5SO4
*/
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class FlashTest extends Sprite {
private var s1:Sprite;
public function FlashTest() {
// write as3 code here..
//addEventListener(MouseEvent.CLICK,onClick);
var node1:node2 = new node2();
addChild(node1);
node1.add(50,50);
node1.add(100,50);
}
/*private function onClick(e:MouseEvent):void{
s1 = new Sprite();
s1.graphics.lineStyle(0,0);
s1.graphics.beginFill(Math.random()*0xffffff);
s1.graphics.drawCircle(0,0,20);
s1.graphics.endFill();
s1.x = stage.mouseX;
s1.y = stage.mouseY;
addChild(s1);
}*/
}
}
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.*;
import flash.geom.*;
//ノードを管理する
class node2 extends Sprite{
private var a:String;
private var b:String;
private var tf:TextField = new TextField();
private var dic:Dictionary = new Dictionary();
public function node2(){
addEventListener(MouseEvent.MOUSE_OVER,onOver);
//addEventListener(MouseEvent.MOUSE_DOWN,func1);
addChild(tf);
tf.border = true;
}
private function onOver(e:MouseEvent):void{
}
private function func1(e:MouseEvent=null):void{
var pt:Point = new Point(mouseX,mouseY);
var o:Array = this.getObjectsUnderPoint(pt);
tf.text = "";
tf.appendText(e.currentTarget.out+"\n");
for(var i:int=0;i<o.length;i++){
tf.appendText(o[i].name+"\n");
}
if(dic[e.currentTarget].out==true)a=dic[e.currentTarget].name;
tf.appendText("\na:"+a);
}
//ノード追加
public function add(nx:Number=0,ny:Number=0):void{
var n:node = new node();
n.x = nx;
n.y = ny;
addChild(n);
n.addEventListener(MouseEvent.MOUSE_DOWN,func1);
dic[n] = n;
}
}
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.*;
//ドラッグ可能
//エッジ接続:ドラッグ&ドロップ
//接続リスト
class node extends Sprite{
private var list:Dictionary;
private var from:Dictionary = new Dictionary();
private var to:Dictionary = new Dictionary();
private var tf:TextField = new TextField();
public function node(){
init();
}
private function init():void{
list = new Dictionary();
graphics.lineStyle(1,0x000000);
graphics.beginFill(0xffffff);
graphics.drawRect(0,-20,100,40);
initIN();
initOUT();
addEventListener(MouseEvent.MOUSE_DOWN,dragNode);
addEventListener(MouseEvent.MOUSE_UP,dropNode);
addChild(tf);
tf.height = 20;
tf.width = 100;
tf.text = "aaa";
tf.selectable = false;
}
//ドラッグ
private function dragNode(e:MouseEvent=null):void{
var _parent:DisplayObjectContainer = this.parent;
this.parent.removeChild(this);
_parent.addChild(this);//オブジェクトを登録しなおして最前面に持ってくる
this.startDrag();
}
private function dropNode(e:MouseEvent=null):void{
this.stopDrag();
}
//入力端子の準備
private function initIN():void{
var entry:EntryPoint = new EntryPoint();
with(entry){
graphics.lineStyle(0,0x000000);
graphics.beginFill(0xffffff);
graphics.drawCircle(0,0,5);
graphics.endFill();
}
addChild(entry);
entry.addEventListener(MouseEvent.MOUSE_OVER,function():void{
with(entry){
graphics.lineStyle(0,0x000000);
graphics.beginFill(0x00ff00);
graphics.drawCircle(0,0,5);
graphics.endFill();
}
});
entry.addEventListener(MouseEvent.MOUSE_OUT,function():void{
with(entry){
graphics.lineStyle(0,0x000000);
graphics.beginFill(0xffffff);
graphics.drawCircle(0,0,5);
graphics.endFill();
}
});
}
private function initOUT():void{
var exit:ExitPoint = new ExitPoint();
with(exit){
graphics.lineStyle(0,0x000000);
graphics.beginFill(0xffffff);
graphics.drawCircle(0,0,5);
graphics.endFill();
x = this.width-5;
}
exit.addEventListener(MouseEvent.MOUSE_DOWN,edge);
addChild(exit);
addChild(line);
exit.addEventListener(MouseEvent.MOUSE_OVER,function():void{
with(exit){
graphics.lineStyle(0,0x000000);
graphics.beginFill(0x00ff00);
graphics.drawCircle(0,0,5);
graphics.endFill();
}
});
exit.addEventListener(MouseEvent.MOUSE_OUT,function():void{
with(exit){
graphics.lineStyle(0,0x000000);
graphics.beginFill(0xffffff);
graphics.drawCircle(0,0,5);
graphics.endFill();
}
});
}
private function edge(e:MouseEvent=null):void{
this.stopDrag();
e.stopPropagation();
var _parent:DisplayObjectContainer = this.parent;
this.parent.removeChild(this);
_parent.addChild(this);//オブジェクトを登録しなおして最前面に持ってくる
addEventListener(Event.ENTER_FRAME,createEdge);
addEventListener(MouseEvent.MOUSE_UP,edge2);
}
private function edge2(e:MouseEvent=null):void{
removeEventListener(Event.ENTER_FRAME,createEdge);
removeEventListener(MouseEvent.MOUSE_UP,edge2);
line.graphics.clear();
}
private var line:Shape = new Shape();
private function createEdge(e:Event):void{
line.graphics.clear();
line.graphics.beginFill(0xff0000);
line.graphics.drawCircle(width-10,0,5);
line.graphics.endFill();
line.graphics.lineStyle(1,0xff0000);
line.graphics.moveTo(width-10,0);
line.graphics.lineTo(mouseX,mouseY);
line.graphics.beginFill(0xff0000);
line.graphics.drawCircle(mouseX,mouseY,5);
line.graphics.endFill();
var pt:Point = new Point(this.parent.mouseX,this.parent.mouseY);
var ar:Array = this.parent.getObjectsUnderPoint(pt);
tf.text = ar[0];
if(ar[0] is EntryPoint){//
tf.text = "OK";
ar[0].list[this] = new Object();
}
else tf.text = "NG";
}
//エッジドロップの検出
private function edge3():void{
}
}
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.*;
import flash.geom.*;
class EntryPoint extends Sprite{
public var list:Dictionary =new Dictionary();
public function EntryPoint(){
}
}
class ExitPoint extends Sprite{
public var list:Dictionary =new Dictionary();
public function ExitPoint(){
}
}
class Node extends Sprite{
public var list:Dictionary =new Dictionary();
public function Node(){
}
public function add(n:Node):void{
list[n] = new Object();
}
public function remove(n:Node):void{
delete list[n];
}
}