On Fri, Dec 26, 2008 at 10:46 PM, Andriy Panas <[email protected]> wrote:

> I have TextArea component on the Stage with embedded font applied,
> then at the runtime I set a bold style to a text inside TextArea to
> "bold" via setTextFormat(newTextFormat) API.
>
> Then, I load at the runtime compiled font from CSS - "Vera.swf" and my
> bold formatting is lost immediately after external font finishes
> loading.
>
>
> Notice, that the second parameter in
> StyleManager.loadStyleDeclarations(fontName, update) call is set in
> the code to "true".
>
> When I change this boolean parameter to "false" - then I will not
> witness that my bold formatting is lost after compiled font finishes
> loading at the runtime.
>
> My question, why when "update" parameter is set to true, I will loose
> all my text formatting changes made at the runtime?
>
> Please have a look at the code below or the run the example from
>
> http://jabbypanda.com/labs/runtimeFont/TestRuntimeFont.html

First of all, getTextField returns an IUITextField, and there's no
method called setTextFormat on IUITextField. So you're casting the
object to its actual type, UITextField, and then calling the
setTextFormat method on it. That's not supported. The reason being
that the TextFormat of the UITextField is determined internally based
on the styles assigned to the object. If you set a TextFormat
explicitly, it may be overwritten at any time by the object.

Now we come to the other part: Why is your TextFormat getting
overwritten when the external stylesheet is loaded?

When you load the external stylesheet, with the second parameter as
true, the entire style cache needs to be regenerated for every object.
And why is that? Let's say your external stylesheet has font-color set
to silver for every Text object. Now since the stylesheet has been
loaded, _every_ Text object must get its styles updated so it can have
silver text.

That explains why your bold setting is getting lost.

If you want to get around that, it should be okay to pass false as the
second argument to loadStyleDeclarations as long as your external
stylesheet really does not affect any existing objects on the screen.

-- 
Manish Jethani
manishjethani.com

Reply via email to