此代码不会产生错误,但TextField不提供输出。 我尝试使用更简单的代码,并且valuelocal有一个值并给出输出但是我需要更小的字体大小,无论如何我需要另一个字体更大的Textfield,所以我确定我需要预加载字体
我指的是。 http://krasimirtsonev.com/blog/article/AS3-flash-runtime-font-loading-embedding
那么这里出了什么问题?
更正 - 我认为输出是结果 - 我得到十几个面板加载而不是输出。切出几行。这些数字来自Main.as
Building New Project
mxmlc -load-config+=obj\NewProjectConfig.xml -debug=true -incremental=true -o obj\NewProject635574676017466150
Starting java as: java.exe -Xmx384m -Dsun.io.useCanonCaches=false -Duser.language=en -Duser.region=US -
INITIALIZING: Adobe Flex Compiler SHell (fcsh)
Starting new compile.
Loading configuration file ...\frameworks\flex-config.xml
Loading configuration file ...\NewProjectConfig.xml
obj\NewProject635574676017466150 (5264 bytes)
(fcsh)Build succeeded
Done(0)
[Starting debug session with FDB]
0
1
2
3
4
5
6
Successfully loaded FontArial (../bin/js/Arial.swf)
Successfully loaded FontArial (../bin/js/Arial.swf)
Successfully loaded FontArial (../bin/js/Arial.swf)
Successfully loaded FontArial (../bin/js/Arial.swf)
Successfully loaded FontArial (../bin/js/Arial.swf)
Successfully loaded FontArial (../bin/js/Arial.swf)
Successfully loaded FontArial (../bin/js/Arial.swf
这是我的代码:
package {
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.text.AntiAliasType;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.text.Font;
import flash.text.TextFieldAutoSize;
/**
* ...
* @author Michael
*/
public class tile extends Sprite {
public static const FONT_NAME:String = "Arial";
public static const FONT_EXPORT_NAME:String = "FontArial";
public static const FONT_FILE_NAME:String = "../bin/js/Arial.swf";
private function onFontLoaded(e:Event):void {
trace("Successfully loaded " + FONT_EXPORT_NAME + " (" + FONT_FILE_NAME + ")");
if (e.target.applicationDomain.hasDefinition(FONT_EXPORT_NAME))
{
var FontClass:Class = e.target.applicationDomain.getDefinition(FONT_EXPORT_NAME) as Class;
Font.registerFont(FontClass);
init();
}
else
{
trace("Missing " + FONT_EXPORT_NAME + "!");
}
}
private function onFontLoadingFailed(e:IOErrorEvent):void {
trace("Missing " + FONT_FILE_NAME);
}
[Embed(source = "C:/my_absolute_local_path/Games/New Project/bin/js/blank.png")]
private var blank:Class;
private var b1:Bitmap;
private var valuelocal:int;
public function tile(value:int):void {
valuelocal = value;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onFontLoaded);
loader.addEventListener(IOErrorEvent.IO_ERROR, onFontLoadingFailed);
loader.addEventListener(IOErrorEvent.NETWORK_ERROR, onFontLoadingFailed);
loader.addEventListener(IOErrorEvent.VERIFY_ERROR, onFontLoadingFailed);
loader.addEventListener(IOErrorEvent.DISK_ERROR, onFontLoadingFailed);
loader.load(new URLRequest(FONT_FILE_NAME));
}
private function init():void {
b1 = new blank ;
this.addChild(b1);
/* var myText:TextField = new TextField();*/
/*myText.antiAliasType = AntiAliasType.ADVANCED;
myText.text = valuelocal.toString();
myText.x = 17;
myText.y = 17;*/
var format:TextFormat = new TextFormat();
format.font = FONT_NAME;
format.size = 20;
format.color = 0x000000;
var field:TextField = new TextField();
field.defaultTextFormat = format;
field.text = valuelocal.toString();
field.x = field.y = 10;
field.embedFonts = true;
field.autoSize = TextFieldAutoSize.LEFT;
this.addChild(field);
}
}
}