October 29, 2005

Embedding fonts in AS3

I love this! ... library, be-gone!

package {
	
import flash.util.describeType;
import flash.display.MovieClip;
import flash.display.TextField;
import flash.text.TextFormat;
import flash.text.AntiAliasType;
  
   public class Test extends MovieClip {
    
      // be sure this is pointing to a ttf font in your hardrive
      [Embed(source="C:\WINDOWS\Fonts\somefont.ttf", fontFamily="foo")] 
      public var bar:String;
      			
      public function Test() {
                	
          var format:TextFormat	      = new TextFormat();
          format.font		      = "foo";
          format.color                = 0xFFFFFF;
          format.size                 = 130;
						
          var label:TextField         = new TextField();
          label.embedFonts            = true;
          label.autoSize              = TextFieldAutoSize.LEFT;
          label.antiAliasType         = AntiAliasType.ADVANCED;
          label.defaultTextFormat     = format;
          label.text                  = "Hello World!";
          addChild(label);
       }
    }
}
Posted by marumushi at 07:53 PM

AS3: attachMovieClip() no more!

aaah, "attachMovieClip"... just the sound of it sounds so retro already. plus... the library?! who the heck needs a library anymore?

kiss the library bye-bye!!
I'm sure we are going to remember these days with a lot of nostalgia.

package {
   import flash.display.MovieClip;
   import flash.display.StageAlign;
   import flash.display.StageScaleMode;
   public class Test extends MovieClip {
      // be sure this is pointing to an image in your hardrive
      [Embed(source='c:\images\whatsup.jpg')] public var MyImage:Class;
      public function Test() {
         stage.align     = StageAlign.TOP_LEFT;
         stage.scaleMode = StageScaleMode.NO_SCALE;
         var img:MyImage = new MyImage();
         addChild(img);
      }
   }
}
Posted by marumushi at 07:49 PM