Chapter 7 Example 16
♥0 |
Line 44 |
Modified 2010-01-03 07:11:53 |
MIT License
archived:2017-03-30 03:23:48
ActionScript3 source code
/**
* Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gbKm
*/
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.system.Security;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFormat;
import com.actionscriptbible.Example;
public class ch17ex16 extends Example {
protected const URL:String =
"http://actionscriptbible.com/files/inconsolata.swf";
protected const CLASSNAME:String =
"com.actionscriptbible.assets.Inconsolata";
protected var l:Loader;
public function ch17ex16() {
Security.allowDomain("actionscriptbible.com", "*.actionscriptbible.com");
Security.loadPolicyFile("http://actionscriptbible.com/crossdomain.xml");
l = new Loader();
l.load(new URLRequest(URL), new LoaderContext(false, ApplicationDomain.currentDomain));
l.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
for each (var f:Font in Font.enumerateFonts()) {trace(f.fontName);}
trace("---");
}
protected function onLoadComplete(event:Event):void {
for each (var f:Font in Font.enumerateFonts()) {trace(f.fontName);}
trace("---");
var domain:ApplicationDomain = l.contentLoaderInfo.applicationDomain;
var fontClass:Class = domain.getDefinition(CLASSNAME) as Class;
Font.registerFont(fontClass);
var tf:TextField = new TextField();
addChild(tf);
tf.defaultTextFormat = new TextFormat("Inconsolata", 28);
tf.width = stage.stageWidth;
tf.height = stage.stageHeight;
tf.multiline = tf.wordWrap = true;
tf.embedFonts = true;
tf.text = "Hello world";
}
}
}