• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

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.

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

Open in new window

1 Solution
erikTsomikSystem Architect, CF programmer Commented:
what version of flex are you on ?
try this instead:

var txt:TextInput = new TextInput();
txt.setStyle("fontWeight", "bold");
txt.setStyle("fontStyle", "italic");

Open in new window

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:


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


Or you can get more complex:

txt1.setStyle("nameOfStyle", txt2.getStyle("nameOfStyle"));
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now