2008年12月18日星期四

TextField代码设置字体问题

代码生成的TextField用代码只能设置英文字体

舞台拉出的TextField可以拿代码设置英文字体,
拿代码设置中文字体则必须要在属性面板选择一个中文字体,才可以设置

在测试的时候发现一件怪事,代码生成的TextField(假设为tf01)无法设置中文字体,但是如果有一个TextField(假设为tf02)是舞台拖出来的,设置一个TextFormat给tf01,中文字体不生效,同时设置给tf02,则tf01的中文字体生效!!!
代码如下:(其中tf02是舞台上拖出来的,并且设置了中文字体)
package{
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
public class Tf extends Sprite {
public var tf01:TextField=new TextField();
public var tff01:TextFormat=new TextFormat();
public var tff02:TextFormat=new TextFormat();
public function Tf() {
tf01.text="dwad中文";
tf01.width=500;
addChild(tf01);
tff01.font="华文彩云";
tff01.size=30;
tff01.color=0xFF0000;
tff02.font="华文琥珀";
tff02.size=40;
tff02.color=0xFF0000; //tf01.appendText("");
tf01.defaultTextFormat=tff02;
tf01.setTextFormat(tff02);
tf02.setTextFormat(tff02);
}
}
}



没经过很好的验证,大体是这样的,请指教...

没有评论: