Posted By

ronniekleinfeldgmailcom on 07/18/12


Tagged

embed external font swf as3


Versions (?)

embed a font from an external swf


 / Published in: ActionScript 3
 

embed a font from an external swf

  1. package ClientLoader
  2. {
  3. import flash.display.Loader;
  4. import flash.display.Sprite;
  5. import flash.events.Event;
  6. import flash.events.IOErrorEvent;
  7. import flash.net.URLRequest;
  8. import flash.text.Font;
  9. import flash.text.TextField;
  10. import flash.text.TextFormat;
  11.  
  12. public class EmbededFonts extends Sprite
  13. {
  14. // embed a font from an external swf
  15. private var _loader:Loader;
  16. private var _fontLibrary:Class;
  17.  
  18. public function EmbededFonts()
  19. {
  20. super();
  21.  
  22. _loader = new Loader();
  23. var urlRequest:URLRequest = new URLRequest("assets/Fonts.swf");
  24. _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, _loader_onIoError);
  25. _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _loader_onComplete);
  26. _loader.load(urlRequest);
  27. }
  28.  
  29. protected function _loader_onIoError(event:IOErrorEvent):void
  30. {
  31. _loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, _loader_onIoError);
  32. trace("failed to load the .swf file");
  33. }
  34. protected function _loader_onComplete(event:Event):void
  35. {
  36. _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, _loader_onComplete);
  37.  
  38. _fontLibrary = event.target.applicationDomain.getDefinition("BernardMTCondensedFont") as Class; // font family name
  39. Font.registerFont(_fontLibrary);
  40.  
  41. DoPaint();
  42. }
  43.  
  44. private function DoPaint():void
  45. {
  46. var textFormat:TextFormat = new TextFormat();
  47. textFormat.font = "Bernard MT Condensed"; // font name
  48. textFormat.bold = true;
  49. textFormat.letterSpacing = 10;
  50.  
  51. var textField:TextField = new TextField();
  52. textField.width = 300;
  53. textField.text = "99:99:99";
  54. textField.textColor = 0x0000ff;
  55. textField.setTextFormat(textFormat);
  56.  
  57. this.addChild(textField);
  58. }
  59. }
  60. }

Report this snippet  

You need to login to post a comment.