Tomtids
Tomtids

Reputation: 128

AS3 font embed from resource file not working

I've done alot of searching on this and not been able to find a solution yet, I hope the board here might help me.

I have set up a project (in the same way I have numerous projects before) that uses a seperate fonts SWF to provide the fonts to my project. Once loaded I register these fonts to the global font directory using Font.registerFont(). My text styles come from an externally loaded style sheet.

For some reason that I cannot figure out, when I try to create a textField and use my embedded fonts the text disapears from screen. If when creating the textField I set embedFonts to false then the text does appear at the right size and colour (as taken from the stylesheet), but obviously with a default system font where my nice custom font should be.

The code I am using is below:

TTWTextHelper.traceAvailableFonts();
TTWTextHelper.traceStyleSheet(myStyleSheet);

var myText = new TextField;
with (myText)
{
     width = 250;

     autoSize = TextFieldAutoSize.LEFT;

     selectable = false;

     antiAliasType = AntiAliasType.ADVANCED;
     styleSheet = myStyleSheet;
     embedFonts = true;
     border = true;

     multiline = true;
     wordWrap = true;

     htmlText = "<span class='body'>Test</body>";
}
myText.x = 300;
myText.y = 300;
addChild(myText);

I know that (apparently) my fonts are embeded as when I run TTWTextHelper.traceAvailableFonts() i get the two fonts listed.

public static function traceAvailableFonts():void
{
   /*
    * See what fonts we have to play with
    */

   var embeddedFonts:Array = Font.enumerateFonts(false);
   embeddedFonts.sortOn("fontName", Array.CASEINSENSITIVE);

   trace("how many fonts? " + embeddedFonts.length);
   Tools.pr(embeddedFonts); 
}

results in:

how many fonts? 2
(array) {
 [0] => (object) [object MarkerFeltThinPlain]
 [1] => (object) [object MarkerFeltWidePlain]
}

and I know that my styleSheet is loaded and is being correctly parsed by actionscript as when i run TTWTextHelper.traceStyleSheet(myStyleSheet); i get the styles listed out correctly:

public static function traceStyleSheet(_styleSheet:StyleSheet):void
{
   trace("Tracing StyleSheet: " + _styleSheet);

   var styles:Array = _styleSheet.styleNames;

   for each(var style : * in styles)
   {
     trace("Style Name: " + style);
     var thisStyle:Object = _styleSheet.getStyle(style);
     Tools.pr(thisStyle); 
   }
}

results in:

Tracing StyleSheet: [object StyleSheet]
Style Name: a
(object) {
    [color] => (string) #ff0000
    [leading] => (string) 2
    [fontFamily] => (string) "MarkerFeltThin-Plain"
    [fontSize] => (string) 15
    [textAlign] => (string) left
}

Style Name: .title
(object) {
    [color] => (string) #ff0000
    [leading] => (string) 2
    [fontFamily] => (string) "MarkerFeltWide-Plain"
    [fontSize] => (string) 20
    [textAlign] => (string) left
}

Style Name: .body
(object) {
    [color] => (string) #4b4b4b
    [leading] => (string) 2
    [fontFamily] => (string) "MarkerFeltThin-Plain"
    [fontSize] => (string) 15
    [textAlign] => (string) left
}

Any advise very much appreciated! Thank you!

Upvotes: 0

Views: 1186

Answers (2)

alxx
alxx

Reputation: 9897

Sometimes embedding font files with [Embed] instead of swf helps (ran into that recently).

Upvotes: 1

PatrickS
PatrickS

Reputation: 9572

Try checking for your fonts fontType property, if the fontType property is "embeddedCFF" , they will not display with a TextField as you would need the Flash Text Engine to render.

Upvotes: 1

Related Questions