I think I would make the font swf do the registration.  That’s how I did it 
recently.  And I always wait for INIT before doing things like that.

package
{
import flash.display.Sprite;
import flash.text.Font;

public class FontLib extends Sprite
{
[Embed(
source="arial.ttf",
fontFamily="Arial"
)]
public static const ARIAL_FONT:Class;

public function FontLib()
{
super();
loaderInfo.addEventListener(Event.INIT, initHandler);
}
}

public function initHandler(event:Event):void
{
Font.registerFont(ARIAL_FONT);
}
}

On 5/7/10 9:15 AM, "aaronius9er9er" <aaronius...@gmail.com> wrote:






The TLF I'm using is from Flex 4.  I've dropped in textLayout.swc from Flex 4 
into the libs directory of a Flex 3.3 project.  This is my main app.  Separate 
from the main app, I have an ActionScript project using the full Flex 4 sdk to 
build the "fonter" class that extends ISWFContext.  The main app is loading in 
the "fonter" swf using a loader context that looks like:

new LoaderContext(false, ApplicationDomain.currentDomain);

In any case, even if I were to figure that out I think I'd run into another 
issue: only a single swf context can be set on a flow composer.  Considering 
our text flow will have multiple fonts (and therefore multiple font swfs), I 
don't see how that would work.  This has been explained more in-depth in posts 
like this one: 
http://marcel-panse.blogspot.com/2010/03/embedded-fonts-in-tlf-and-swfcontexts.html

So...I've gone to yet another approach: calling Font.registerFont() to register 
the font that's been embedded in a separate font swf.  The separate font swf 
will no longer extend ISWFContext.  I realize my font swf resources will never 
be unloaded from memory but that's okay.

Now my setup is that both my main app swf and my font swf are built using the 
Flex 3.3 sdk.

I'm not even worrying about the textflow or TLF at all yet.  I just want to be 
able to load in a font swf, register the font, then enumerate the fonts and see 
it listed as an embedded font in the main app.

When calling Font.registerFont(), I get the following error:

ArgumentError: Error #1508: The value specified for argument font is invalid.
 at flash.text::Font$/registerFont()
 at FontApp/completeHandler()[C:\Development\TLF\FontApp\src\FontApp.mxml:24]

Here's my code for the main app:

--------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute" 
minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;

protected var loader:Loader;

protected function application1_creationCompleteHandler(event:FlexEvent):void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
var request:URLRequest = new 
URLRequest('http://aaronhardy.com/transfer/FontLib.swf');
loader.load(request);
}

protected function completeHandler(event:Event):void
{
var FontLib:Class = 
event.currentTarget.applicationDomain.getDefinition("FontLib") as Class;
var Arial:Class = FontLib.ARIAL_FONT;
Font.registerFont(Arial);
var fonts:Array = Font.enumerateFonts(false);
trace(fonts);
}
]]>
</mx:Script>
</mx:Application>

--------------------------------------

And here's my code for the font swf:

--------------------------------------

package
{
import flash.display.Sprite;
import flash.text.Font;

public class FontLib extends Sprite
{
[Embed(
source="arial.ttf",
fontFamily="Arial"
)]
public static const ARIAL_FONT:Class;

public function FontLib()
{
super();
}
}
}

--------------------------------------

I've tried both verdana and arial fonts that I've pulled from my 
C:\Windows\Fonts folder and it always throws the error.  Once I get this 
resolved I should be able to get started with the text flow integration.

Aaron

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , Alex 
Harui <aha...@...> wrote:
>
> So let's back up a second.  Which version of TLF are you using?  The one from 
> Flex 4 or and older one?  I don't know if older ones exist and are still 
> valid, but they did not use iSWFContext until recently.
>
> How are you loading the font SWF?  If you don't use a child or same 
> applicationDomain topology then (fonter is ISWFContext) would return false.
>
>
> On 5/6/10 4:55 PM, "aaronius9er9er" <aaronius...@...> wrote:
>
>
>
>
>
>
> To no avail, I've decided to take a different route.  I decided to make an 
> ActionScript project with a class that implements ISWFContext and embeds the 
> font I need.  Then from my main app I load the class in and set it on 
> flowComposer's swfContext property.  This is explained well with a good 
> example here:
>
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flashx/textLa
>  yout/compose/ISWFContext.html
>
> So, I make the font class implement ISWFContext and then in my app I have the 
> following:
>
> ------------------------
>
> var fonter:Object = loader.content;
> trace(describeType(fonter));
> trace(fonter is ISWFContext);
> editor.textFlow.flowComposer.swfContext = ISWFContext(fonter);
>
> ------------------------
>
> On the describeType trace it shows:
>
> ------------------------
>
> <type name="Fonter" base="flash.display::Sprite" isDynamic="false" 
> isFinal="false" isStatic="false">
>  <metadata name="__go_to_ctor_definition_help">
>  <arg key="file" value="C:\Development\TLF\Fonter\src\Fonter.as"/>
>  <arg key="pos" value="371"/>
>  </metadata>
>  <metadata name="__go_to_definition_help">
>  <arg key="file" value="C:\Development\TLF\Fonter\src\Fonter.as"/>
>  <arg key="pos" value="169"/>
>  </metadata>
>  <extendsClass type="flash.display::Sprite"/>
>  <extendsClass type="flash.display::DisplayObjectContainer"/>
>  <extendsClass type="flash.display::InteractiveObject"/>
>  <extendsClass type="flash.display::DisplayObject"/>
>  <extendsClass type="flash.events::EventDispatcher"/>
>  <extendsClass type="Object"/>
>  <implementsInterface type="flash.display::IBitmapDrawable"/>
>  <implementsInterface type="flashx.textLayout.compose::ISWFContext"/>
>  ...
>
> ------------------------
>
> Notice it shows the class as implementing ISWFContext as planned.  But on the 
> next line I trace whether fonter is of type ISWFContext and it reports false. 
>  On the next line where I attempt to cast it to ISWFContext I get the 
> following error:
>
> TypeError: Error #1034: Type Coercion failed: cannot convert fon...@a32ce81 
> to flashx.textLayout.compose.ISWFContext.
>  at 
> TLFTester/fontLoadedHandler()[C:\Development\TLF\TLFTester\src\TLFTester.mxml:70]
>
> I'm going crazy over here.  The app is built using the flex 3.3 sdk.  The 
> font swf is built using the flex 4 sdk.  The textLayout.swc should be the 
> same (I pulled the textLayout.swc from the flex 4 sdk to use in our flex 3.3 
> app).
>
> Any ideas?
>
> BTW, does Adobe offer any sort of official developer support?  We'd gladly 
> pay consulting rates as we're in the midst of a large, expensive project.
>
> Thanks,
>
> Aaron
>
> --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>  
> <mailto:flexcoders%40yahoogroups.com> , Alex Harui <aharui@> wrote:
> >
> > If you're trying to load the font by placing it in an RSL, make sure it is 
> > last in the list of RSLs to load ( or at least not first or second).
> >
> >
> > On 5/6/10 10:42 AM, "aaronius9er9er" <aaronius9er@> wrote:
> >
> >
> >
> >
> >
> >
> > Strange.  When I link to the library project using "Merged into code" it 
> > works, but when linking to it as an RSL it throws the following error when 
> > running the app:
> >
> > VerifyError: Error #1014: Class mx.core::FontAsset could not be found.
> >
> > Google doesn't have a whole lot to say on the issue. I get this error even 
> > if I compile my font library project using the 3.3 SDK.
> >
> > Aaron
> >
> > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>  
> > <mailto:flexcoders%40yahoogroups.com>  
> > <mailto:flexcoders%40yahoogroups.com> , "aaronius9er9er" <aaronius9er@> 
> > wrote:
> > >
> > > Nevermind, that's related to my code.  More testing to come...
> > >
> > > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>  
> > > <mailto:flexcoders%40yahoogroups.com>  
> > > <mailto:flexcoders%40yahoogroups.com> , "aaronius9er9er" <aaronius9er@> 
> > > wrote:
> > > >
> > > > Thanks for the response. I created a library project with an 
> > > > EmbeddedFonts class compiled using the Flex 4 sdk.  I then linked to 
> > > > the library and made sure the app was referencing the class:
> > > >
> > > > protected var fontsLinkage:EmbeddedFonts;
> > > >
> > > > but then I get the following error when attempting to run the app:
> > > >
> > > > TypeError: Error #1034: Type Coercion failed: cannot convert 
> > > > _tlftester_mx_managers_systemmana...@139860b1 to 
> > > > flashx.textLayout.compose.ISWFContext.
> > > > at 
> > > > TLFTester/fontLoadedHandler()[C:\Development\TLF\TLFTester\src\TLFTester.mxml:52]
> > > > at 
> > > > TLFTester/application1_creationCompleteHandler()[C:\Development\TLF\TLFTester\src\TLFTester.mxml:25]
> > > > at 
> > > > TLFTester/___TLFTester_Application1_creationComplete()[C:\Development\TLF\TLFTester\src\TLFTester.mxml:3]
> > > > at flash.events::EventDispatcher/dispatchEventFunction()
> > > > at flash.events::EventDispatcher/dispatchEvent()
> > > > at 
> > > > mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.3.0\frameworks\projects\framework\src\mx\core\UIComponent.as:9308]
> > > > at mx.core::UIComponent/set 
> > > > initialized()[C:\autobuild\3.3.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1169]
> > > > at 
> > > > mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.3.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:718]
> > > > at Function/http://adobe.com/AS3/2006/builtin::apply()
> > > > at 
> > > > mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.3.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8633]
> > > > at 
> > > > mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.3.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8573]
> > > >
> > > > I would assume it's due to a difference in SDKs.  You didn't run into 
> > > > the same issue?
> > > >
> > > > Aaron
> > > >
> > > >
> > > > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> > > >  <mailto:flexcoders%40yahoogroups.com>  
> > > > <mailto:flexcoders%40yahoogroups.com> , gabriel montagné <gabriel@> 
> > > > wrote:
> > > > >
> > > > > Hello Aaron,
> > > > >
> > > > > On 06/05/2010, aaronius9er9er <aaronius9er@> wrote:
> > > > > >
> > > > > > We have an app built in Flex 3.3.  We've pulled the text layout 
> > > > > > framework
> > > > > > swc from Flex 4 to use in our app.  We now need to load fonts 
> > > > > > dynamically at
> > > > > > runtime to use within our text flow.  In my understanding, in order 
> > > > > > to
> > > > >
> > > > > We've also had to use the TLF with CFF fonts in a Flex 3.* app... we 
> > > > > didn't
> > > > > have to load them at runtime but we compiled a swc with them and 
> > > > > linked that on
> > > > > the main app.
> > > > >
> > > > > Perhaps you could do something like that with a RSL if you need to 
> > > > > load them
> > > > > dynamically.
> > > > >
> > > > > But, most importantly, for the fonts to be linked you don't really 
> > > > > need the swf
> > > > >  compiled with the new sdk to be a full flex app.  In our case it was 
> > > > > just a
> > > > > plain class with the fonts embedded:
> > > > >
> > > > > package uk.co.razorfish.fonts
> > > > > {
> > > > >
> > > > > /**
> > > > >  *  This class embedds the fonts needed for the TLF which is used for 
> > > > > the
> > > > >     ...
> > > > >  */
> > > > > public class EmbeddedFonts
> > > > > {
> > > > >
> > > > >     [Embed(
> > > > >         source="tt1047m_.ttf",
> > > > >         fontFamily="Industrial736 BT",
> > > > >         fontStyle="regular",
> > > > >         cff="true",
> > > > >         advancedAntiAliasing="true",
> > > > >         unicodeRange="U+0020-007F, U+00A0-00FF, U+2010-201F,
> > > > > U+2032-2037, U+2039-203A, U+20A0-20B5"
> > > > >     )]
> > > > >     public static const INDUSTRIAL_ROMAN:Class;
> > > > >
> > > > >     [Embed(
> > > > >         source="tt1048m_.ttf",
> > > > >         fontFamily="Industrial736 BT",
> > > > >         fontStyle="italic",
> > > > >         cff="true",
> > > > >         advancedAntiAliasing="t
> > > > >
> > > > > ... etc.
> > > > >
> > > > > Because we needed to load them up front, on the main app, we just 
> > > > > linked that
> > > > > class,
> > > > >
> > > > > import uk.co.razorfish.fonts.EmbeddedFonts; EmbeddedFonts;
> > > > >
> > > > > And that did the job.
> > > > >
> > > > > HTH,
> > > > > Gabriel
> > > > >
> > > > > --
> > > > > gabriel montagné láscaris comneno
> > > > > http://rojored.com
> > > > > +44 (0) 7500 709 209
> > > > >
> > > >
> > >
> >
> >
> >
> >
> >
> >
> > --
> > Alex Harui
> > Flex SDK Team
> > Adobe System, Inc.
> > http://blogs.adobe.com/aharui
> >
>
>
>
>
>
>
> --
> Alex Harui
> Flex SDK Team
> Adobe System, Inc.
> http://blogs.adobe.com/aharui
>






--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui

Reply via email to