2016-10-13 00:16:48 点击量:9 标签: 收藏本文
使用HTML的标签,或者设置TextFormat对象的font属性,或者通过CSS的font-family属性
修改字体有多种方法,如果使用HTML的话可通过 标签更改:field.htmlText = "Formatted text";
也可设置TextFormat对象的font属性:formatter.font = "Arial";
或者在CSS中定义font-family 属性:p {font-family: Arial;}
需要注意的是电脑中必须要有你所指定的字体,因为有些电脑上可能没有安装相应的字体,这是可指定多种字体:formatter.font = "Arial, Verdana, Helvetica";
如果都没有指定字体,默认使用系统字体。
另外我们还可使用字体组,字体组是系统默认字体的一个分类,有三种: _sans, _serif, 和_typewriter。
_sans 组包含如Arial 或Helvetica,_serif组包含如Times 或Times New Roman,_typewriter 组包含如Courier 或Courier New
嵌入字体
通过[embed]元数据嵌入字体,设置文本框的embedFonts属性为true,通过标签,TextFormat对象或CSS应用字体
嵌入系统字体:
[Embed(systemFont="Onyx",fontName="hxw",mimeType="application/x-font-truetype")]
嵌入非系统字体:
[Embed(source="xjlFont.fon",fontName="xjl",mimeType="application/x-font")]
可以设置textField.rotation = 30来设置文字旋转(放在定时器或OnEnterFrame事件里),文字必须为嵌入字体,否则无法正常显示。
- package {
- import flash.display.Sprite;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFormat;
- [Embed(source="xjlFont.fon",fontName="xjl",mimeType="application/x-font-truetype")]
- public class Sample0410 extends Sprite
- {
- public function Sample0410()
- {
- var textBox:TextField = new TextField();
- textBox.text = "hello everybody,my name is cuplayer.com";
- textBox.autoSize = TextFieldAutoSize.CENTER;
- textBox.embedFonts=true;
- addChild(textBox);
- var formatter:TextFormat = new TextFormat();
- formatter.font = "xjl";
- formatter.size = 30;
- textBox.setTextFormat(formatter);
- }
- }
- }
CSS方式
- package {
- import flash.display.Sprite;
- import flash.text.StyleSheet;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- [Embed(source="xjlFont.fon",fontName="xjl",mimeType="application/x-font-truetype")]
- public class Sample0410 extends Sprite
- {
- public function Sample0410()
- {
- var css:StyleSheet = new StyleSheet();
- var styleObj:Object = {color:"#FFFF00", fontFamily:"xjl",fontSize:"30px"};
- css.setStyle(".stdStyle",styleObj);
- var textBox:TextField = new TextField();
- textBox.styleSheet = css;
- textBox.text = "<span class='stdStyle'>hello everybody,my name is 老胡</span>";
- textBox.autoSize = TextFieldAutoSize.CENTER;
- textBox.embedFonts=true;
- addChild(textBox);
- }
- }
- }
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室