setTextFormat

by hacker_yk666qry
...
@author ...
♥0 | Line 30 | Modified 2010-01-10 16:24:43 | MIT License
play

ActionScript3 source code

/**
 * Copyright hacker_yk666qry ( http://wonderfl.net/user/hacker_yk666qry )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3bQm
 */

package {
	
	import flash.display.Sprite;
	import flash.text.*;
	
	/**
	 * ...
	 * @author ...
	 */
	public class MyTextField extends Sprite {
		public var tf:TextField;
		public var format0:TextFormat, format1:TextFormat, format2:TextFormat;
		
		// コンストラクタ
		public function MyTextField() {
			format0 = makeTextFormat( "_typewriter", 18, 0x000000 );
			format1 = makeTextFormat( "_serif", 32, 0x000000 );
			format2 = makeTextFormat( "_typewriter", 32, 0xff0000 );
			
			tf = new TextField();
			tf.x = 10;
			tf.y = 100;
			tf.autoSize = TextFieldAutoSize.LEFT;
			
			tf.defaultTextFormat = format0;
			tf.text = "楽しいActionScriptの世界へ";
			
			tf.setTextFormat( format1, 0, 1 );
			tf.setTextFormat( format2, 3, 15 );
			tf.setTextFormat( format1, 16, 18 );
			addChild( tf );
		}
		
		// 書式の設定
		public function makeTextFormat( font:String, size:uint, color:uint ):TextFormat {
			var format:TextFormat = new TextFormat();
			format.font = font;
			format.size = size;
			format.color = color;
			return format;
		}
	}
	
}