Using Link Events in TextField
tf = new TextField();
tf.selectable = false;
tf.defaultTextFormat = new TextFormat("_sans", 14);
tf.multiline = tf.wordWrap = true;
tf.width = 200;
tf.htmlText = "This text controls itself. You could turn it" +
’ <a href="event:color,0xff0000"><u>red</u></a> or’ +
’ <a href="event:color,0x00ff00"><u>green</u></a>. Or you could’ +
’ <a href="event:move,20,0"><u>move it right</u></a> or’ +
’ <a href="event:move,0,20"><u>move it down</u></a>.’;
tf.addEventListener(TextEvent.LINK, onLink);
addChild(tf);
}
protected function onLink(event:TextEvent):void {
var args:Array = event.text.split(",");
if (args.length < 1) return;
switch (args.shift()) {
case "color":
colorText.apply(this, args);
break;
case "move":
moveText.apply(this, args);
break; } }
获取当前系统的字体
import flash.text.Font;
var fonts:Array = Font.enumerateFonts(true);
for each (var font:Font in fonts) {
if (font.fontName.match(/^comic\b/i) != null) {
found = true;
break;
}
}
}
}
}
Pass it trueto include all device fonts; omit this parameter or use
false to include only embedded fonts. This method returns an array of Fontinstances
fontStyle— The style of this font. Bold, italic, and bold+italic versions of the font must be embedded independently if you are to use any text in that font and style. All these embedded fonts will be instances of Fontwith the same fontNamebut different fontStyles. This property is one of the constants FontStyle.REGULAR, FontStyle.BOLD, FontStyle.ITALIC, or FontStyle.BOLD_ITALIC.
fontType— Whether the font is a device font, an embedded font, or a embedded CFF font. These values are defined as constants in FontType.
But the most important duty of Fontis to register new fonts. If you load a SWF with an embedded font, you’ll need to do this step before you can use the font in TextFields. Once the embedded font is registered with Font, it can be referenced by font name by TextFormats and the like. Use the static method Font.registerFont()to enable a font for use by passing its Classreference.