186 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 5 000 and 10 000 dollars
  • United States
scottrockers says

Really good idea bitfade, thanks, bookmarked.

4140 posts
  • Bought between 1 and 9 items
  • Brazil
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
tsafi says

load External Font simple way Dispatch class (for CS3)
package 
{
    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.IOErrorEvent;
    import flash.net.URLRequest;
    import flash.system.ApplicationDomain;
    import flash.text.Font;

         //Font Loader
    public class ExternalFont extends EventDispatcher
    {
        public static const COMPLETE:String = "fontLoad";
        public static const ERROR:String    = "error";

        private var _ld:Loader;
        private var _Dom:ApplicationDomain;
        private var _Font:Array;
        private var _fontClass:Class;

        // ExternalFont Dispatcher url & font name
        public function ExternalFont(_url:String,fonts:Array):void
        {
            _ld = new Loader();
            _Font = fonts;

    //_ld.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, _onIOError);
            _ld.contentLoaderInfo.addEventListener(Event.COMPLETE, _complete);

            var req = new URLRequest(_url);
            _ld.load(req);
        }

        // if fonts  loaded you can pull fonts if you whant

        public function get(_setId:String):Font {            
            return _Dom.getDefinition(_setId) as Font;
        }

        //set extract fonts on Complete
        private function _complete(e:Event):void {
            _Dom = _ld.contentLoaderInfo.applicationDomain;
            var i:Number;
            for (i = 0; i < _Font.length; i++) {
                _fontClass = _Dom.getDefinition(_Font[i]) as Class;
                Font.registerFont(_fontClass);
            }

            dispatchEvent(new Event(ExternalFont.COMPLETE));
        }

        //if IOErrorEvent set Arial
        //private function _onIOError(e:IOErrorEvent):void {
        //    dispatchEvent(new Event(ExternalFont.ERROR));
        //}
    }
}

main class
var _font:ExternalFont = new ExternalFont("swfFont.swf", ["MyFont"]);//registerFont in swfFont.swf (MyFont)
var txt:TextField=new TextField();
var tf:TextFormat=new TextFormat();
_font.addEventListener(ExternalFont.COMPLETE, _complete );
//_font.addEventListener(ExternalFont.ERROR, _error);

//function _error(e:Event) {
//    tf.font="Arial"; // if error set Arial .
//    txt.embedFonts = false;
//    setFormat();
//}

function _complete (e:Event) {
    var embeddedFonts:Array = Font.enumerateFonts(false);
    tf.font=embeddedFonts[0].fontName;
    txt.embedFonts = true;
    setFormat();
}

function setFormat(){
    tf.size = 16;
    txt.defaultTextFormat = tf;
    //txt.x = 0;
    //txt.y = 0;
    //txt.autoSize = TextFieldAutoSize.LEFT;
    txt.htmlText = "Hit me Baby";
    addChild(txt);
}

1 post
  • Has been a member for 2-3 years
  • Ukraine
NEvgeniy says
tsafi said

load External Font ...

Very useful, tnx!=)

by
by
by
by
by
by