I altered the code a little and got it half working.  It works if you're setting the imported font using setStyle, but not if you're setting the font through the TextFormat object.  Simply add the lines:

                var content:DisplayObject = ldr.content;
                var c:Class = content["myFont"];
                Font.registerFont(c);

to the begining of onloadercomplete.

I'm going to continue working on how to get the font to show up through TextFormat.


On 8/29/06, Daniel Wabyick <[EMAIL PROTECTED]> wrote:
I just tried to dynamically load a font at runtime, and the results are
not too promising.

For other's benefits, here is what I did:

- Created an AS3 project and generated a SWF (SymbolEmbed.swf) with the
Symbol font embedded.

- Verified the font is available in the SWF via Font.enumerateFonts();

- Loaded SymbolEmbed.swf into a Flex app using the Loader class,
following instructions to keep the SWF's on the same applicationDomain.

- Checked if the font is available to the Flex app, it is not.

Please let me know if anyone has any ideas,

-Daniel




Code: AS3 project with embedded font.
-------------------
    public class SymbolInclude extends Sprite
    {
        public function SymbolInclude()
        {
            [Embed(systemFont='Symbol', fontName='mySymbol',
mimeType='application/x-font')]
            var myFont:Class;

            trace("here in SymbolInclude");
            var fontList : Array = Font.enumerateFonts();
            for ( var i:String in fontList )
            {
                trace("font: " + Font( fontList[i] ).fontName);
            }
        }
    }


Code: Loader code in Flex app.
-------------------------------------------

<mx:Script>
         <![CDATA[

             private var ldr:Loader;
             private function onInit() : void
             {
                 showFonts();

                 var context:LoaderContext = new LoaderContext();
                 //context.securityDomain = SecurityDomain.currentDomain;
                 context.applicationDomain =
ApplicationDomain.currentDomain;

                 ldr = new Loader();
                 ldr.contentLoaderInfo.addEventListener( Event.COMPLETE,
onLoaderComplete );
                 ldr.load( new URLRequest( "SymbolInclude.swf"), context );
             }

             private function onLoaderComplete(e:Event) : void
             {
                 trace("onLoaderComplete: ");
                 showFonts();
             }

             public function showFonts():void {
                 trace("showFonts()");
                  var fontList : Array = Font.enumerateFonts ();
                    for ( var i:String in fontList )
                    {
                        trace("font: " + Font( fontList[i] ).fontName);
                    }
                   }
         ]]>
     </mx:Script>






Daniel Freiman wrote:
>
> I have this question too but it hasn't reached the top of my to-do
> list yet.  What I'm hoping is that is that you can embed a font in a
> swf and then load that swf at runtime using a swfloader.
>
> On 8/28/06, *Daniel Wabyick* < [EMAIL PROTECTED]
> <mailto: [EMAIL PROTECTED]>> wrote:
>
>     Hey guys,
>
>     Is there any way to include a font at runtime using Flex 2?  There
>     was a
>     weird hack that works in Flash 8 where you load a movie that loads an
>     RSL. Does anything like this work in Flex 2 ?
>
>     Thanks,
>     -Daniel
>
>
>     --
>     Flexcoders Mailing List
>     FAQ:
>     http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
>     < http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt >
>     Search Archives:
>     http://www.mail-archive.com/flexcoders%40yahoogroups.com
>     < http://www.mail-archive.com/flexcoders%40yahoogroups.com>
>     Yahoo! Groups Links
>
>     < http://groups.yahoo.com/group/flexcoders/>
>
>     <mailto:[EMAIL PROTECTED]>
>
>     < http://docs.yahoo.com/info/terms/ >
>
>
>
>
>
>



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
     [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/




__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to