TextField_setTextFormat
♥0 |
Line 32 |
Modified 2009-10-13 10:55:03 |
MIT License
archived:2017-03-09 15:15:26
ActionScript3 source code
/**
* Copyright oshige ( http://wonderfl.net/user/oshige )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gaq0
*/
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;
}
}
}