//文字列の表示
class LabelEx {
//コンストラクタ
function LabelEx(mc:MovieClip) {
//HelloWorld
addLabel(mc,"Hello World!");
//24ドットの赤い文字を(0,20)に描画
var test1:TextField=addLabel(mc,"1234567890");
test1.setXY(0,20);
test1.setFontColor(0xFF0000);
test1.setFontSize(24);
}
//ラベルの追加
static function addLabel(parent:MovieClip,
text:String):TextField {
//初期値
if (text==undefined) text="";
//インスタンス名の自動生成
if (parent.nameIdx==undefined) parent.nameIdx=0;
var name:String="_name"+(parent.nameIdx++);
//テキストフィールドの追加
parent.createTextField(name,
parent.getNextHighestDepth(),0,0,0,0);
var mc:TextField=parent[name];
mc.autoSize ="left";//オートサイズ
mc.selectable=false; //選択不可
mc.text=text; //テキスト
mc._x =0; //X座標
mc._y =0; //Y座標
//書式
mc.format=new TextFormat();
mc.format.font ="_等幅"; //フォント
mc.format.size =12; //文字サイズ
mc.format.color=0x000000;//文字色
mc.setTextFormat(mc.format);
//XY座標の指定
mc.setXY=function(_x:Number,_y:Number) {
this._x=_x;
this._y=_y;
}
//テキストの指定
mc.setText=function(_text:String) {
this.text=_text;
this.setTextFormat(this.format);
}
//文字サイズの指定
mc.setFontSize=function(size:Number) {
this.format.size=size;
this.setTextFormat(this.format);
}
//文字色の指定
mc.setFontColor=function(color:Number) {
this.format.color=color;
this.setTextFormat(this.format);
}
return mc;
}
//メイン
static function main() {
var app:LabelEx=new LabelEx(_root);
}
}
|