ボタンを作ってみるテスト
package{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import caurina.transitions.Tweener;
[SWF(backgroundColor="0xf0f0f0", frameRate="30")]
public class ButtonTest extends MovieClip{
public function ButtonTest():void{
var stage:MovieClip = this;
for(var i:Number = 0; i < 10; i++){
var b:Button = new Button('button' + i.toString());
b.x = 20;
b.y = 30 + i * 24;
(function():void{
var m:String = i.toString() + ' が押されたよ';
b.addEventListener(MouseEvent.MOUSE_DOWN, function(e:Event):void{
var message:TextField = new TextField();
stage.addChild(message);
message.text = m;
message.autoSize = TextFieldAutoSize.LEFT;
message.selectable = false;
message.x = Math.random() * 400;
message.y = Math.random() * 400;
Tweener.addTween(message, {
x: 80 + Math.random() * 300,
y: 80 + Math.random() * 300,
time: 0.5,
transition: 'easeOutExpo'
});
message.addEventListener(Event.ENTER_FRAME, function(e:Event):void{
message.x += 1 - Math.random() * 2;
message.y += 1 - Math.random() * 2;
});
});
})();
stage.addChild(b);
}
}
}
}
import flash.display.*;
import flash.text.*;
class Button extends SimpleButton{
function Button(text:String){
this.upState = (function():Sprite{
var s:Sprite = new Sprite();
s.graphics.lineStyle(1, 0xa0a0a0);
s.graphics.beginFill(0xafafaf);
s.graphics.drawRect(0, 0, 50, 20);
s.addChild(generate_label(text));
return s;
})();
this.overState = (function():Sprite{
var s:Sprite = new Sprite();
s.graphics.lineStyle(1, 0xa0a0a0);
s.graphics.beginFill(0xc0c0c0);
s.graphics.drawRect(0, 0, 50, 20);
s.addChild(generate_label(text));
return s;
})();
this.downState = (function():Sprite{
var s:Sprite = new Sprite();
s.graphics.lineStyle(1, 0xa0a0a0);
s.graphics.beginFill(0xcfcfcf);
s.graphics.drawRect(2, 2, 50, 20);
var t:TextField = generate_label(text);
t.x = 2;
t.y = 2;
s.addChild(t);
return s;
})();
this.hitTestState = this.overState;
}
private function generate_label(text:String):TextField{
var t:TextField = new TextField();
t.text = text;
t.autoSize = TextFieldAutoSize.LEFT;
t.selectable = false;
return t;
}
}