flash on 2011-10-21
・フリーハンドのラインを作る
・ラインを時系列に保存する
・
♥0 |
Line 56 |
Modified 2011-10-21 18:35:50 |
MIT License
archived:2017-03-30 03:01:45
ActionScript3 source code
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ywGj
*/
package {
/*
・フリーハンドのラインを作る
・ラインを時系列に保存する
・
*/
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
public class FlashTest extends Sprite {
private var points:Object;
private var cnt:int = 0;
private var s1:Shape = new Shape();
private var s2:Sprite = new Sprite();
private var t1:TextField = new TextField();
public function FlashTest() {
// write as3 code here..
t1.text = "aaaa";
s2.graphics.beginFill(0x00ffff);
s2.graphics.drawRect(0,0,400,400);
s2.graphics.endFill();
addChild(s2);
addChild(t1);
s2.addEventListener(MouseEvent.MOUSE_DOWN,down1);
}
private function down1(e:MouseEvent):void{
var ar:Array = new Array();
//points[cnt] = ar;
t1.text = "down1";
stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
stage.addEventListener(MouseEvent.MOUSE_UP,endLine);
addChild(s1);
}
private function onMove(e:MouseEvent):void{
t1.text = "onMove";
addLine(mouseX,mouseY);
}
private function addLine(x:Number=0,y:Number=0):void{
var point:Point = new Point(x,y);
points[cnt].push(point);
s1.graphics.clear();
s1.graphics.lineStyle(2,0x000000);
var i:int=0;
s1.graphics.moveTo(points[cnt][0].x,
points[cnt][0].y);
for(i=1;i<points[cnt].length;i++){
s1.graphics.lineTo(points[cnt][i].x,
points[cnt][i].y);
}
}
private function endLine(e:MouseEvent):void{
cnt++;
stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
stage.removeEventListener(MouseEvent.MOUSE_UP,endLine);
var i:int;
t1.text = "";
for(i=0;i<points[cnt-1].length;i++){
t1.appendText(points[cnt-1][i].x.toString()+"\n");
}
}
}
}