forked from: TextField_setTextFormat
forked from TextField_setTextFormat (diff: 1)
ActionScript3 source code
/**
* Copyright Peach_man ( http://wonderfl.net/user/Peach_man )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/2kPU
*/
// forked from oshige's TextField_setTextFormat
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class MyTextField extends Sprite {
public var fld:TextField;
public var tf0:TextFormat, tf1:TextFormat, tf2:TextFormat;
//コンストラクタ
public function MyTextField(){
tf0 = makeTextFormat("_typewriter", 18, 0x000000);
tf1 = makeTextFormat("_serif", 32, 0x000000);
tf2 = makeTextFormat("_typewriter", 32, 0xFF0000);
//テキストフィールドの作成
fld = new TextField();
fld.x = 20;
fld.y = 50;
fld.autoSize = TextFieldAutoSize.LEFT;
//書式の初期値
fld.defaultTextFormat = tf0;
fld.text = "楽しいActionScriptの世界へ";
//入力済みのテキストに書式を設定
fld.setTextFormat(tf1, 0, 1);//楽
fld.setTextFormat(tf2, 3, 15);//ActionScript
fld.setTextFormat(tf1, 16,18 );//世界
addChild(fld);
}
//書式の作成
public function makeTextFormat(font:String, size:uint, color:uint):TextFormat {
var tf:TextFormat = new TextFormat();
tf.font = font;
tf.size = size;
tf.color = color;
return tf;
}
}
}
