Chapter 17 Example 6
♥0 |
Line 31 |
Modified 2009-06-29 06:44:55 |
MIT License
archived:2017-03-09 15:17:52
ActionScript3 source code
/**
* Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/2vuJ
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class ch17ex6 extends Sprite {
public function ch17ex6() {
//A
var tf:TextField = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
addChild(tf);
var fmt:TextFormat = new TextFormat();
fmt.font = "_sans";
fmt.bold = true;
fmt.size = 24;
tf.defaultTextFormat = fmt;
//note that you have to set the default format BEFORE setting the text
//it applies to all NEW text added.
tf.text = "be bold.";
//B
tf = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
tf.y = 50;
tf.text = "RED GREEN BLUE";
addChild(tf);
var redFmt:TextFormat = new TextFormat("_sans", 20, 0xff0000);
var greenFmt:TextFormat = new TextFormat("_sans", 20, 0x00ff00);
var blueFmt:TextFormat = new TextFormat("_sans", 20, 0x0000ff);
var t:String = tf.text;
tf.setTextFormat(redFmt, t.indexOf("RED"), t.indexOf("RED")+3);
tf.setTextFormat(greenFmt, t.indexOf("GREEN"), t.indexOf("GREEN")+5);
tf.setTextFormat(blueFmt, t.indexOf("BLUE"), t.indexOf("BLUE")+4);
}
}
}