此代码不会将文本呈现到屏幕上。改变,
drawText.embedFonts = false;呈现文本,但字体大小或颜色不会修改。
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.*;
public class DrawText extends Sprite {
private var drawText:TextField;
private var myFormat:TextFormat;
[Embed(source="c:/windows/fonts/verdana.ttf", fontFamily="Verdana", embedAsCFF="false")]
private var verdana:Class;
public function DrawText(mX:int,mY:int){
myFormat = new TextFormat("Verdana");
myFormat.size = 32;
myFormat.color = 0x00FFFF;
drawText = new TextField();
drawText.embedFonts = true;
drawText.autoSize = TextFieldAutoSize.LEFT;
drawText.selectable = false;
drawText.type = "dynamic";
drawText.multiline=true;
drawText.wordWrap=true;
drawText.x = 128;
drawText.y = 128;
drawText.text = "TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST";
drawText.defaultTextFormat = myFormat;
addChild(drawText);
}//END constructor
}//END class
}//END package这真的很令人沮丧,任何帮助都会非常感谢。我使用的是Flash Builder 4.6。
发布于 2013-07-18 19:12:09
应在设置text之前应用defaultTextFormat,或对现有文本使用TextField.setTextFormat
更新:对于embedFonts,你必须在使用之前注册字体类:
Font.registerFont(verdana);UPD2:
示例(修改主题中的代码):
//set defaultTextFormat before set text
//and use setTextFormat to format existed text
drawText.defaultTextFormat = myFormat;
drawText.setTextFormat(myFormat);
drawText.text = "TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST";发布于 2013-07-18 19:12:51
您应该使用drawText.setTextFormat(myFormat);
https://stackoverflow.com/questions/17721804
复制相似问题