SimpleButton
イベントをtraceするだけのシンプルなボタンです。
♥0 |
Line 71 |
Modified 2011-03-24 12:53:36 |
MIT License
archived:2017-03-20 16:52:54
ActionScript3 source code
/**
* Copyright t2421 ( http://wonderfl.net/user/t2421 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ffA8
*/
package {
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.display.Sprite;
public class Bts extends Sprite {
private var bt:En;
private var tf:TextField;
public function Bts() {
// write as3 code here..
TraceText.init();
tf = new TextField();
tf.height = 500;
this.addChild(tf);
tf.text = "traceArea";
bt = new En();
this.addChild(bt);
bt.x = stage.stageWidth/2;
bt.y = stage.stageHeight/2;
setEvent();
}
private function setEvent():void{
bt.buttonMode = true;
bt.addEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
bt.addEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
bt.addEventListener(MouseEvent.CLICK,clickHandler);
}
private function clickHandler(e:MouseEvent):void{
TraceText.traceText("click",tf);
}
private function rollOverHandler(e:MouseEvent):void{
TraceText.traceText("rollOver",tf);
}
private function rollOutHandler(e:MouseEvent):void{
TraceText.traceText("rollOut",tf);
}
}
}
import flash.text.TextFormat;
import flash.text.TextField;
import flash.display.Sprite;
class En extends Sprite{
public function En(_radius:Number=50,_lineThickness:Number=10,_color:uint=0xff0000,_lineColor:uint=0x000000){
graphics.lineStyle(_lineThickness,_lineColor);
graphics.beginFill(_color);
graphics.drawCircle(0,0,_radius);
graphics.endFill();
}
}
class TraceText{
static private var _textHistory:String;
static private const MAX_COL:uint = 30;//max col of reset
static private var counter:uint = 0;
public function TraceText(){
}
static public function init():void{
_textHistory = "";
}
static public function traceText(str:String,tf:TextField):void{
_textHistory += str+"\n";
tf.text = _textHistory;
counter++;
if(counter >= TraceText.MAX_COL){
resetText(tf);
counter=0;
}
}
static public function resetText(tf:TextField):void{
_textHistory = "";
tf.text = _textHistory;
}
static public function get textHistory():String{return _textHistory}
}