tags:

views:

297

answers:

2

Is there a way to bind a Label's fontSize to be half the fontSize of another label?

I tried this:

<mx:Label id="mytitle" text="{title}" fontSize="{(mylabel.getStyle('fontSize') as Number)/2}"/>

No luck...anyone know a way?

Thanks

A: 

What you tried gets called too early, so the font for "mylabel" isn't initialized yet. You could use the initialize event to do this after the UI components are filled in.

<mx:Label id="mytitle" text="{halfSize}"
          initialize="{setStyle('fontSize', mylabel.getStyle('fontSize') / 2)}"/>
Kevin Beck
Hi, that will set it on init, but will it be binded if the myLabel's font size changes? Thanks.
John Isaacks
+1  A: 

Your chosen method won't work because getStyle isn't bindable. You could always bind both labels to some other value (one to it unmodified and one to that value divided by 2) and change that rather than the font size on the label itself.

The existence of a good solution might depend on why you want to do this though.

inferis