Link to home
Start Free TrialLog in
Avatar of jchittoda1
jchittoda1Flag for India

asked on

runtime CSS change in flex

Hi All,

I am working in Flex. I want to set style bold / italic / underline depending upon the selection of a buttons.
I am using the following to set the font style/weight but it is not working.

I want to set the bold and italic formatting dynamically upon clicking BOLD or ITALIC button given in the application.

Please help me with this.

Thanks
var txt:TextInput = new TextInput();
txt.setStyle("font-weight", "bold");
txt.setStyle("font-style", "italic");

Open in new window

Avatar of erikTsomik
erikTsomik
Flag of United States of America image

what version of flex are you on ?
ASKER CERTIFIED SOLUTION
Avatar of Fuzzy_Logic_
Fuzzy_Logic_
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hockeyragazzo
hockeyragazzo

Surprisingly (and annoyingly) CSS in Flex uses different style property names than are used in Flex. So, as Fuzzy Logic pointed out, while inside a <Style> tag you need to say "font-weight," when you're setting the style dynamically in Actionscript, you need to use the Flex-standard names for the properties: "fontWeight."

Another example:

background-color = backgroundColor

The full list of component properties can be found in the Flex docs from Adobe. In particular, here it is for the TextInput component:

http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html#styleSummary

As you already know, you say txt.setStyle("nameOfStyle", "propertyValue"); or you can get the style like this:

txt.getStyle("nameOfStyle");

Or you can get more complex:

txt1.setStyle("nameOfStyle", txt2.getStyle("nameOfStyle"));