drawing dialog and buttons on 2010-6-24
import flash.text.TextFormat;
import flash.text.TextField;
/**
* Copyright hermit ( http://wonderfl.net/user/hermit )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zoPU
*/
package {
//import flash.text.TextFormat;
//import flash.text.TextField;
import flash.display.Sprite;
[SWF(backgroundColor = 0x000000)]
public class FlashTest extends Sprite {
public function FlashTest() {
//message.defaultTextFormat = new TextFormat(null, null, 0xffffff);
//message.y = 400;
//addChild(message);
//message.text = String(width);
addChild(new Dialog('Who marks first?',
'You', you1st, 'Me', me1st));
}
private function you1st():void
{
}
private function me1st():void
{
}
}
}
import flash.geom.Matrix;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.display.GradientType;
//var message:TextField = new TextField;
//message.autoSize = TextFieldAutoSize.LEFT;
const textPoint:uint = 52; // ダイアログとボタンに使う文字の大きさ(ポイント)
class GradientBox extends Sprite
{
function GradientBox(_width:uint, _height:uint, _x:uint = 0, _y:uint = 0)
{
var m:Matrix = new Matrix();
m.createGradientBox(_width, _height,
Math.PI / 2); // rotation, 90 degrees
// createGradientBox(200, 100, Math.PI / 2)
// #=> Matrix(7.474404015029158e-18, 0.06103515625, -0.1220703125, 3.737202007514579e-18, 100, 50)
//message.text = 'm(' +
// String(m.a) + ', ' + String(m.b) + ', ' +
// String(m.c) + ', ' + String(m.d) + ',\n' +
// String(m.tx) + ', ' + String(m.ty) + ')';
with (graphics) {
beginGradientFill(GradientType.LINEAR,
[0x333333, 0x666666],
[0.8, 0.8],
[0, 80],
m);
drawRoundRect(_x, _y, _width, _height, 30, 30);
}
}
}
class Dialog extends GradientBox
{
function Dialog(msg:String, b1str:String, b1fn:Function, b2str:String, b2fn:Function)
{
// TODO
// [ ] 計算して中央に配置する
// [ ] 大きさを計算で決める
// [x] 位置決定をDialogのコンストラクタに入れる
x = 9;
y = 100;
var _width:uint = 450;
var _height:uint = 300;
var _x:uint = 0;
var _y:uint = 0;
const thickness:uint = 2;
with (graphics) {
lineStyle(thickness, 0xffffff);
//drawRoundRect(0, 0, _width, _height, 30, 30);
//_width -= thickness * 2;
//_height -= thickness * 2;
//_x += thickness;
//_y += thickness;
//lineStyle(1, 0);
//drawRoundRect(3, 3, _width, _height, 30, 30);
//_width -= 2; _height -= 2;
}
super(_width, _height, _x, _y);
with (addChild(new TextField())) {
defaultTextFormat = new TextFormat("Arial", textPoint, 0xffffff);
autoSize = TextFieldAutoSize.LEFT;
text = msg;
selectable = false;
x = (parent.width - width) / 2;
y = (parent.height - height) / 3.3;
}
var b1:Button = new Button(b1str);
b1.x = 16;
b1.y = 182;
addChild(b1);
with (addChild(new Button(b2str))) {
x = b1.x * 2 + b1.width;
y = b1.y;
}
}
}
class Button extends GradientBox
{
function Button(s:String,
_width:uint = 200, _height:uint = 100)
{
buttonMode = true;
mouseChildren = false;
const thickness:uint = 1;
with (graphics) {
lineStyle(thickness, 0xffffff);
drawRoundRect(0, 0, _width, _height, 30, 30);
_width -= thickness * 2;
_height -= thickness * 2;
lineStyle(1, 0);
}
super(_width, _height, thickness, thickness);
with (addChild(new TextField)) {
//border = true;
//borderColor = 0x00ff00;
defaultTextFormat = new TextFormat("Arial", textPoint, 0xffffff);
text = s;
autoSize = TextFieldAutoSize.LEFT;
//selectable = false;
x = (parent.width - width) / 2;
y = (parent.height - height) / 2;
}
}
}