Hey folks! I’ve been a long-time lurker and user of these forums, and decided it was time to pose my stumper for you gurus.
This is exclusively an AS2 issue (I believe) - I have an external class (through a MovieClip’s linkage) that in due course creates a textField, and attempts to use an embedded font.
I’m familiar with the conventional way of doing this when not using an external class: create a Font library item, export for actionscript, create your TextField, create a TextFormat object, set the font to the Font item’s linkage name, set embedFonts to true.
However, when I’m trying to do this from the external .as file, it’s not seeing the Font library item in the calling (main) flash file.
I thought I had a clever solution: create another swf that only contains the Font asset, exported for runtime; then use a movieClipLoader inside the external class to load the font.swf into the external AS file’s context so it would be able to “find” the font.
As far as I can tell, that idea was a bust.
Any thoughts? I’m attaching my class file below.
It does the following:
- loads the font.swf movie (I was hoping that this would make the embedded font available to my class!)
- waits for it to complete loading
- creates a new TextField object
- creates a new TextFormat object, sets the font size to 24, assigns the font name of “Tahoma24” (the name of my exported font library item)
- assigns the TextFormat object to my TextField
- puts some sample text in.
As you can see, the whole shooting match doesn’t do squat. If you comment out the “embedFonts” line, the text displays fine (though not in Tahoma of course).
class embeddedFontTest extends MovieClip {
public var str:String = "";
public var mc_fonts:MovieClip;
public var loadedClips:Object = {
mc_fonts:0
}
public function embeddedFontTest(){
this.createEmptyMovieClip("mc_fonts", this.getNextHighestDepth());
var fontLoader:MovieClipLoader = new MovieClipLoader()
var flListener:Object = new Object();
flListener.onLoadInit = function(mc:MovieClip) { mc._parent.registerLoadComplete(mc) };
fontLoader.addListener(flListener);
fontLoader.loadClip("fonts.swf", this.mc_fonts);
}
private function registerLoadComplete(mc:MovieClip){
loadedClips[mc._name] = 1;
var loadComplete:Boolean = true;
for (var i:String in loadedClips){
if (! loadedClips*) loadComplete = false;
}
if (loadComplete) startApplication();
}
private function startApplication(){
trace("starting");
var txtCode:TextField = this.createTextField("txt_test", this.getNextHighestDepth(), 0, 0, 100, 100);
var fmt:TextFormat = new TextFormat();
fmt.font = "Tahoma24";
fmt.size = 24;
fmt.color = 0x000000;
txtCode.setTextFormat(fmt);
txtCode.autoSize = "left";
txtCode.selectable = false;
txtCode.type = "static";
txtCode.border = true;
txtCode.embedFonts = true;
txtCode.text = "Hello World";
}
}
Thanks guys! Look forward to your comments.