Chapter 17 Example 16

by actionscriptbible
♥0 | Line 33 | Modified 2010-01-27 13:59:45 | MIT License
play

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/fXFQ
 */

package {
  import flash.display.*;
  import flash.events.Event;
  import flash.net.URLRequest;
  import flash.system.*;
  import flash.text.*;
  public class ch17ex16 extends Sprite {
    protected const URL:String = 
      "http://actionscriptbible.com/files/inconsolata.swf";
    protected const CLASS_NAME:String =
      "com.actionscriptbible.assets.Inconsolata";  
    protected var loader:Loader;
    
    public function ch17ex16() {
      loader = new Loader();
      loader.load(new URLRequest(URL), new LoaderContext(
        true, null, SecurityDomain.currentDomain));
      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
    }
    protected function onLoadComplete(event:Event):void {
      var domain:ApplicationDomain = loader.contentLoaderInfo.applicationDomain;
      var fontClass:Class = domain.getDefinition(CLASS_NAME) as Class;
      Font.registerFont(fontClass);
      
      var tf:TextField = new TextField();
      addChild(tf);
      tf.defaultTextFormat = new TextFormat("Inconsolata", 64);
      tf.antiAliasType = AntiAliasType.ADVANCED
      tf.width = stage.stageWidth; tf.height = stage.stageHeight;
      tf.multiline = tf.wordWrap = true;
      tf.embedFonts = true;
      tf.text = "Hello world";
    }
  }
}