Monday 26 January 2009

Flash: Embedded Fonts in Subsets and Submovies

Ok, this entry lines up in the endless queue of Blogs, Stories and Forum-entries about the most annoying issue in Flash: Embedding fonts and dealing with external Assets/Flashfiles.

Hell, I was almost cracking. Using Gaia and trying to do it this way led me to nowhere. (more about it here and here). Despite being able to SEE the font in all submovies, applying text and a textformat-object just made all text either completely or partially disappear. No clue what and why and...

It seemed as if only one particular range of characters makes it into the Submovie. My special problem was to get the "®"-Character into the text which was added to all embedded Textfields as suggested.

Only, it wouldn't work. But then: just out of randomness I created a MovieClip-class for the elements which had the textfields in it, made all text-assignments via this class and BAM! All there suddenly, special chars, normal chars, everything nicely showing up!

To sum it up: applying text and formats in Submovies directly via the Document class: Meeeep - Njet work. Instead: Always create proxy classes by hand, make a function to apply text (i.e.: "setText") and deal with the formatting in there.

Here such a proxy class:


package com.example.views
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
/**
* ...
* @author Me
*/
public class CurrentItem extends MovieClip
{

public var titleTXT:TextField;
public var data:Object;
private var textFormat:TextFormat;

public function CurrentItem()
{
titleTXT.autoSize = TextFieldAutoSize.RIGHT;
titleTXT.mouseEnabled = false;
buttonMode = true;
}
public function setTitle( str:String ):void
{
setText( titleTXT, str );
}
private function setText( tf:TextField, str:String ):void
{
textFormat = tf.getTextFormat();
textFormat.letterSpacing = 0;
tf.embedFonts = true;
tf.text = str;
tf.setTextFormat( textFormat );
}
}
}



then use it like this in your Document class:

subItem.setTitle( "HELLO!®" );

And all your miseries about embedded Fonts are history.

Obviously there needs to be a Font.swf being loaded somewhere, sitting in the memory, having called

"Font.registerFont( _Helvetica );"

for instance. See the above link for this matter.

No comments: