I've found an issue (in flash cs5) when using TLFTextfields and fonts shared at runtime, and I wondered if anyone has a solution.
Here's the scenario.
Fonts.swf: library for fonts (runtime
shared DF4)
Popup.swf: popup with a
TLFTextfield (with text in it) using
a font from Fonts.swf
Main.swf : the
main swf with a button that loads and
unloads Popup.swf (using Loader or
SafeLoader give the same
results)
Nice and simple,
Run main.swf, click button and the popup appears with the text. Click the button again to remove the popup. All well and good now click the button again and I get the following error.
ArgumentError: Error #1508: The value specified for argument font is invalid.
at flash.text::Font$/registerFont()
at Popup_fla::MainTimeline()[Popup_fla.MainTimeline::MainTimeline:12]
I'm presuming it's happening because the font is already registered (checked when clicking before the load).
Does anyone know how to get past this?
If you are wondering here's my Main.as
package
{
import fl.controls.Button;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.events.UncaughtErrorEvent;
import flash.net.URLRequest;
import flash.text.Font;
public class Main extends Sprite
{
public var testPopupBtn:Button;
protected var loader:Loader;
public function Main()
{
trace("Main.Main()");
testPopupBtn.label = "open";
testPopupBtn.addEventListener(MouseEvent.CLICK, testClickHandler);
}
protected function testClickHandler(event:MouseEvent):void
{
trace("Main.testClickHandler(event)");
if(loader)
{
testPopupBtn.label = "open";
this.removeChild(loader);
//loader.unloadAndStop();
loader = null;
}else{
testPopupBtn.label = "close";
trace("Registered Fonts -->");
var fonts:Array = Font.enumerateFonts(false);
for each (var font:Font in fonts) {
trace("\t",font.fontName, font.fontStyle, font.fontType);
}
trace("<--");
loader = new Loader();
loader.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
this.addChild(loader);
try{
loader.load(new URLRequest("Popup.swf"));
}catch(e:*){
trace(e);
}
}
}
private function uncaughtErrorHandler(event:UncaughtErrorEvent):void
{
trace("Main.uncaughtErrorHandler(event)", event);
}
}
}