flash on 2010-3-18
//これはポケモソの努力値計算に便利なツールにしようと思っています。
//Checkクラスは引用です。
/**
* Copyright venthels ( http://wonderfl.net/user/venthels )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gmcD
*/
////これはポケモソの努力値計算に便利なツールにしようと思っています。
////Checkクラスは引用です。
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
import flash.event.MouseEvent;
import flash.event.Event;
public class FlashTest extends Sprite {
private var pokename:TextField = new TextField();
private var pokelus:Check;
private var h:Check, a:Check, b:Check, c:Check, d:Check, s:Check;
private var CurFightTf:TextField = new TextField();
private var TarFightTf:TextField = new TextField();
private var btn1:btn, btn2:btn, btn3:btn;
private var logTf:Log;
public function FlashTest() {
pokename.border = true;
pokename.x = 10;
pokename.y = 15;
pokename.width = 150;
pokename.height = 20;
pokename.text = "名前入力欄";
pokename.type = TextFieldType.INPUT;
addChild(pokename);
pokelus = new Check(this,false,10,50,75, "ポケルス" ,0xff00ff );
h = new Check(this,false,100,50,90, "ウェイト(H)" ,0x000000 );
a = new Check(this,false,100,70,90, "リスト(A)" ,0x000000 );
b = new Check(this,false,100,90,90, "ベルト(B)" ,0x000000 );
c = new Check(this,false,100,110,90, "レンズ(C)" ,0x000000 );
d = new Check(this,false,100,130,90, "バンド(D)" ,0x000000 );
s = new Check(this,false,100,150,90, "アンクル(S)" ,0x000000 );
fighting();
btn1 = new btn(100, 400, 0x00ff00);
btn1.setTxt("+1");
addChild(btn1);
btn1.addEventListener(MouseEvent.MOUSE_DOWN, btnMD);
btn2 = new btn(100, 350, 0x0000ff);
btn2.setTxt("+2");
addChild(btn2);
btn2.addEventListener(MouseEvent.MOUSE_DOWN, btnMD);
logTf = new Log();
logTf.x = 200;
logTf.y = 200;
addChild(logTf);
}
private function fighting():void {
TarFightTf.x = 220;
TarFightTf.y = 30;
TarFightTf.text = "目標";
addChild(TarFightTf);
CurFightTf.x = 300;
CurFightTf.y = 30;
CurFightTf.text = "現在";
addChild(CurFightTf);
var tfAry:Array = new Array();
var total:int = 510;
for(var i:int=0; i<2; i++) {
for(var j:int=0; j<6; j++) {
tfAry.push(new TextField());
var l:int = tfAry.length-1;
tfAry[l].text = "0";
tfAry[l].x = 220 + i*70;
tfAry[l].y = 50 + j*20;
tfAry[l].width = 40;
tfAry[l].height = 20;
if(i == 0) {
////mokuryo-
tfAry[l].type = TextFieldType.INPUT;
tfAry[l].border = true;
total += int(tfAry[l].text);
}
else {
////gennzai
}
addChild(tfAry[l]);
}
}
var totalTf:TextField = new TextField();
totalTf.x = 200;
totalTf.y = 180;
totalTf.width = 70;
totalTf.height = 20;
totalTf.text = "total = " + String(total);
addChild(totalTf);
/*
var TarStat:TextField = new TextField();
TarStat.border = true;
TarStat.autoSize = TextFieldAutoSize.RIGHT;
TarStat.type = TextFieldType.INPUT;
TarStat.text = "0\n0\n0\n0\n0\n0";
TarStat.x = 240;
TarStat.y = 50;
addChild(TarStat);
*/
}
private function btnMD(e:MouseEvent):void {
e.target.graphics.clear();
g.beginFill(0xff0000);
g.lineStyle(1.0, 0x000000, 1.0);
g.drawRect(0, 0, 80, 40);
g.endFill();
}
}
}
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
//import flash.display.Graphics;
import flash.display.*;
//import flash.system.*;
//import flash.geom.*;
import flash.text.*
class Plate extends Sprite {
protected var txt:TextField;
protected var Width:int;
public function Plate(pp:Sprite,X:int,Y:int,W:int,s:String):void {
x=X;
y=Y;
txt=new TextField();
txt.text=s;
txt.height=18;
txt.width=W-20;
txt.y=0;
txt.selectable = false;
addChild(txt);
Width=W;
buttonMode=true;
writeNormal();
pp.addChild(this);
}
protected function writeNormal():void {
graphics.clear();
graphics.lineStyle(1,0xaaaaaa);
graphics.beginFill(0xdddddd);
graphics.drawRect(0,0,Width-1,17);
graphics.endFill();
graphics.lineStyle(1,0x666666);
graphics.moveTo(1,17);
graphics.lineTo(Width-1,17);
graphics.lineTo(Width-1,1);
}
}
class MessagePlate extends Plate {
private var normalTxt:String;
private var messageTxt:String;
private var normalColor:int;
private var messageColor:int;
public function MessagePlate(pp:Sprite,X:int,Y:int,W:int,s1:String,s2:String,c1:int=0,c2:int=0xff0000):void {
super(pp,X,Y,W,s1);
normalTxt=s1;
messageTxt=s2;
normalColor=c1;
messageColor=c2;
Off();
}
public function On():void {
txt.text=messageTxt;
txt.textColor=messageColor;
}
public function Off():void {
txt.text=normalTxt;
txt.textColor=normalColor;
}
}
class ClickablePlate extends Plate {
public function ClickablePlate(pp:Sprite,X:int,Y:int,W:int,s:String):void {
super(pp,X,Y,W,s);
buttonMode=true;
addEventListener(MouseEvent.MOUSE_UP,MUp);
addEventListener(MouseEvent.MOUSE_OVER,MOver);
addEventListener(MouseEvent.MOUSE_OUT,MOut);
}
public function MUp(e:Event):void {
;
}
public function MOut(e:Event):void {
writeNormal();
}
public function MOver(e:Event):void {
writeHilight();
}
protected function writeHilight():void {
graphics.clear();
graphics.lineStyle(1,0xffffff);
graphics.beginFill(0xdddddd);
graphics.drawRect(0,0,Width-1,17);
graphics.endFill();
graphics.lineStyle(1,0xaaaaaa);
graphics.moveTo(1,17);
graphics.lineTo(Width-1,17);
graphics.lineTo(Width-1,1);
}
}
class Check extends ClickablePlate {
private var val:Boolean;
private var box:Sprite;
public function Check(pp:Sprite,now:Boolean,X:int,Y:int,W:int,l:String,c:int=0):void {
super(pp,X,Y,W,l);
val=now;
txt.x=16;
txt.textColor=c;
box=new Sprite();
box.buttonMode=true;
addChild(box);
write();
}
public override function MUp(e:Event):void {
toggle();
dispatchEvent(new Event("update",true));
}
public function setValue(a:Boolean):void {
val=a;
write();
}
public function isChecked():Boolean {
return val;
}
public function toggle():void {
setValue(!val);
}
public function update():void {
write();
}
public function write():void {
box.graphics.clear();
box.graphics.lineStyle(1,0);
box.graphics.beginFill(0xffffff);
box.graphics.drawRect(1,1,14,14);
box.graphics.endFill();
if( val ) {
box.graphics.lineStyle(2,0);
box.graphics.moveTo(2,11);
box.graphics.lineTo(4,11);
box.graphics.lineTo(6,13);
box.graphics.lineTo(14,3);
}
}
}
class btn extends Sprite {
private var my_col:uint = 0xdddddd;
private var my_txt:String;
private var my_tf:TextField = new TextField();
private var my_sp:Sprite = new Sprite();
private var g:Graphics = my_sp.graphics;
public function btn(_x:Number=0, _y:Number=0, _c:uint=0xdddddd):void {
my_sp.x = _x;
my_sp.y = _y;
my_col = _c;
g.clear();
g.beginFill(my_col);
g.lineStyle(1.0, 0x000000, 1.0);
g.drawRect(0, 0, 80, 40);
g.endFill();
my_sp.buttonMode = true;
my_sp.addEventListener(MouseEvent.MOUSE_DOWN, btnDown);
my_sp.addEventListener(MouseEvent.MOUSE_UP, btnUp);
my_sp.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
my_tf.selectable =false;
my_sp.addChild(my_tf);
addChild(my_sp);
}
private function btnDown(e:MouseEvent):void {
/*
g.clear();
g.beginFill(0xff0000);
g.lineStyle(1.0, 0x000000, 1.0);
g.drawRect(0, 0, 80, 40);
g.endFill();
*/
}
private function btnUp(e:MouseEvent):void {
g.clear();
g.beginFill(my_col);
g.lineStyle(1.0, 0x000000, 1.0);
g.drawRect(0, 0, 80, 40);
g.endFill();
}
private function btnOut(e:MouseEvent):void {
g.clear();
g.beginFill(my_col);
g.lineStyle(1.0, 0x000000, 1.0);
g.drawRect(0, 0, 80, 40);
g.endFill();
}
public function setTxt(_txt:String):void {
my_tf.text = _txt;
}
}
class Log extends Sprite {
private var tf:TextField = new TextField();
public function Log():void {
tf.border = true;
tf.width = 220;
tf.height = 240;
addChild(tf);
}
}