Created
February 15, 2012 06:29
-
-
Save wwwins/1833765 to your computer and use it in GitHub Desktop.
font loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.Loader; | |
import flash.display.Sprite; | |
import flash.events.Event; | |
import flash.net.URLRequest; | |
import flash.text.Font; | |
import flash.text.TextField; | |
import flash.text.TextFieldAutoSize; | |
import flash.text.TextFormat; | |
public class Main extends Sprite | |
{ | |
private var loader:Loader; | |
public function Main() | |
{ | |
if (stage) | |
init(); | |
else | |
addEventListener(Event.ADDED_TO_STAGE, init); | |
} | |
private function init(e:Event = null):void | |
{ | |
removeEventListener(Event.ADDED_TO_STAGE, init); | |
// entry point | |
loader = new Loader(); | |
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); | |
// project is here "as3_test\font\FontLibrary" | |
loader.load(new URLRequest("FontLibrary.swf")); | |
} | |
private function completeHandler(event:Event):void | |
{ | |
trace("Complete"); | |
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler); | |
for each (var f:Font in Font.enumerateFonts()) | |
{ | |
trace("fontName:"+f.fontName); | |
} | |
var myTextBox:TextField = new TextField(); | |
myTextBox.defaultTextFormat = new TextFormat("FontName", 28, 0x2DAAFD, true); | |
myTextBox.autoSize = TextFieldAutoSize.LEFT; | |
myTextBox.embedFonts=true; | |
myTextBox.selectable = false; | |
myTextBox.text = "1234567890勇敢追逐自己的夢和色彩"; | |
addChild(myTextBox); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment