The issue I'm encountering is if I immediately instantiate an asset loaded that requires an asset from a RSL, sometimes the RSL has not initialized yet, and null is returned for the Font Class ArialRegular. Other times I get a "Reference Error".

How might I check for the proper initialization of an RSL and loaded assets? Checking for a null class works sometimes for when the accessed class itself returns null, but when there is instead a Reference Error checking for Null won't help.

I've used RSL for better or worse for many years so I have extensive experience with it. The problem I'm encountering seems specific to Fonts.

Solution: I answered my question below.

2

There are 2 answers

2
ktamlyn On BEST ANSWER

OK, I've found a solution that points to a cause that cannot be corrected but can be avoided.

Basically if you have TextFields (classic, or TLF) that use the fonts you have embedded via a RSL they need to be dynamically created at run time. They cannot be a part of the original SWF asset that was loaded. Static text is OK, but dynamic and input text that requires an RSL asset messes up, unless it is dynamically generated after the Font asset has been loaded.

This is one of those subtle issues that I have figured out in the past, and wish I hadn't forgotten about.

1
divillysausages On

I'm not 100% on dynamic RSLs, as I tend to use static linking, so I'm not sure if you have to specifically load them yourself, or if the player does it for your automatically. In any case:

1) Loading it yourself: you should have a callback, and thus know when it's loaded 2) Automatically loaded: you can loop every frame and check for the existence of a class that you know is in the RSL, using getDefinitionByName() - when it stops returning null, then your RSL is loaded.

Either way, if your assets require your RSL, then you're going to have to load that first, before loading the assets - it might slow down your app start up, but then, that's the nature of dependencies.

For something like a font, I'd just embed in the main SWF - as long as your not embedding the entire thing, it's not really that big; you can use the unicodeRange and either specify glyphs, or use the ranges defined in flex_config.xml file - I've written about embedding fonts here if you want to take a look at it: http://divillysausages.com/blog/as3_font_embedding_masterclass

Another thing to check when you have problems with fonts not appearing, if it multiple assets declare the same font. E.g. if swfA declares Arial with the glyphs a-z, while swfB declares Arial with the glyphs 0-9, then depending on which swf is loaded first, your textfields will only display either letters or numbers (with embedFonts set to true). I'm not sure if this is by design or a bug in the flash player, but it's stung me before