forked from: DotEditor
参考 http://ma1.s203.xrea.com/wordpress/archives/23
/**
* Copyright hacker_aft9cz2z ( http://wonderfl.net/user/hacker_aft9cz2z )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hUGO
*/
// forked from hacker_aft9cz2z's DotEditor
//参考 http://ma1.s203.xrea.com/wordpress/archives/23
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.text.TextField;
public class DotEditor extends Sprite
{
public function DotEditor()
{
// write as3 code here..
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
//this.createTextField("my_txt", this.getNextHighestDepth(), 0, 0, 60, 20);
my_txt = new TextField();
my_txt.x=360;
my_txt.y=20;
my_txt.width=60;
my_txt.height=20;
this.addChild(my_txt);
my_txt.maxChars=8;
my_txt.border=true;
my_txt.type="input";
my_txt.text = "0x000000";
for(var i:int=0; i<pix_x; i++)
{
for(var n:int=0; n<pix_y; n++)
{
this.graphics.lineStyle(1,0xEEEEEE);
this.graphics.moveTo(0+pix_sizes*i, 0+pix_sizes*n);
this.graphics.lineTo(pix_sizes*(i+1), 0+pix_sizes*n);
this.graphics.lineTo(pix_sizes*(i+1), pix_sizes*(n+1));
this.graphics.lineTo(0+pix_sizes*i, pix_sizes*(n+1));
this.graphics.lineTo(0+pix_sizes*i, 0+pix_sizes*n);
}
}
}
/**
* プロパティ
*/
private var pix_sizes:int = 20;//12;
private var pix_x:int = 16;
private var pix_y:int = 16;
private var point_x:Number = 0;
private var point_y:Number = 0;
private var lastx:Number;
private var lasty:Number;
private var my_txt:TextField;
/**
* メソッド
*/
private function mouseDownHandler(e:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
hoge();
}
private function mouseUpHandler(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
private function mouseMoveHandler(e:MouseEvent):void
{
hoge();
e.updateAfterEvent();
}
private function hoge():void
{
var x:int = mouseX - mouseX % pix_sizes;
var y:int = mouseY - mouseY % pix_sizes;
dotWrite(x,y);
}
private function dotWrite(x:int=10, y:int=10):void
{
trace(x,":",y)
if(x == lastx && y == lasty)
{
return;
}
else
{
lastx = x;
lasty = y;
}
if(
x < point_x ||
y < point_y ||
x >= pix_x * pix_sizes + point_x ||
y >= pix_y * pix_sizes + point_y
)
{
return;
}
this.graphics.beginFill(Number(my_txt.text));
this.graphics.lineStyle(1,0xEEEEEE)
//this.graphics.beginFill(0x000000);
this.graphics.moveTo(0+x, 0+y);
this.graphics.lineTo(pix_sizes+x, 0+y);
this.graphics.lineTo(pix_sizes+x, pix_sizes+y);
this.graphics.lineTo(0+x, pix_sizes+y);
this.graphics.lineTo(0+x, 0+y);
this.graphics.endFill();
}
}
}