简体   繁体   English

在实例化使用共享库资产的类之前,如何确保在Flash / Flex中已加载RSL?

[英]How do I make sure a RSL in Flash/Flex, is loaded prior to instantiating a class that uses a shared library asset?

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. 我遇到的问题是,如果我立即实例化需要从RSL加载资产的资产,有时RSL尚未初始化,并且字体类ArialRegular返回null。 Other times I get a "Reference Error". 有时我会收到“参考错误”。

How might I check for the proper initialization of an RSL and loaded assets? 如何检查RSL和已加载资产的正确初始化? 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. 当访问的类本身返回null时,检查null类有时会起作用,但是当出现引用错误时,检查Null不会起作用。

I've used RSL for better or worse for many years so I have extensive experience with it. 我使用RSL的好坏有很多年了,所以我对此有丰富的经验。 The problem I'm encountering seems specific to Fonts. 我遇到的问题似乎是字体所特有的。

Solution: I answered my question below. 解决方案:我在下面回答了我的问题。

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. 我不是100%使用动态RSL,因为我倾向于使用静态链接,因此我不确定是否必须自己专门加载它们,或者播放器是否自动为您加载。 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. 1)自己加载它:您应该有一个回调,从而知道它何时加载2)自动加载:您可以循环播放每个帧,并使用getDefinitionByName()检查RSL中是否存在一个已知的类-当何时它停止返回null ,然后加载您的RSL。

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. 无论哪种方式,如果资产需要RSL,则必须先加载该资源,然后再加载资产-这可能会减慢应用程序的启动速度,但这就是依赖关系的本质。

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; 对于诸如字体之类的东西,我只是嵌入主SWF中-只要您不嵌入整个内容,它就不会那么大。 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 您可以使用unicodeRange并指定字形,也可以使用flex_config.xml文件中定义的范围-如果您想看一下字体,我已经在此处写过有关嵌入字体的信息: 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. 如果有多个资产声明相同的字体,则在字体不出现问题时要检查的另一件事。 Eg if swfA declares Arial with the glyphs az, 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). 例如,如果swfA用字形az声明Arial,而swfB用字形0-9声明Arial,则取决于首先加载的swf,文本字段将只显示字母或数字( embedFonts设置为true)。 I'm not sure if this is by design or a bug in the flash player, but it's stung me before 我不确定这是设计使然还是Flash播放器中的错​​误,但我之前很怕

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. 基本上,如果您的TextField(经典或TLF)使用通过RSL嵌入的字体,则需要在运行时动态创建它们。 They cannot be a part of the original SWF asset that was loaded. 它们不能成为已加载的原始SWF资产的一部分。 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. 静态文本是可以的,但是需要RSL资产的动态和输入文本会混乱,除非在加载Font资产动态生成。

This is one of those subtle issues that I have figured out in the past, and wish I hadn't forgotten about. 这是我过去发现的那些细微问题之一,希望我没有忘记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM