Home > Flex > Flex Tip of the Day: inline styles not permitted on UITextField

Flex Tip of the Day: inline styles not permitted on UITextField

(One in a series of random, daily, useful Flex tips.)

In Flash, when you want to draw raw text, you use a TextField. In Flex, when you want to draw text and apply CSS styles, you use a UITextField, which adds support for CSS as well as many other things.

Because you can set the styleName of the UITextField and reference CSS values on it, you might also be tempted to think that you can also call setStyle() on it to set an inline style. But no, you can’t. There’s a setStyle() implementation in UITextField that does exactly nothing. This is documented, but it’s easy to miss.

I’m not sure why this method is there. I had guessed it was because it needed to be there in order to completely implement some interface, but I can’t find an interface that UITextField implements that has a setStyle() method in it. Anyone know?

Depending on why you needed to set an inline style, you might be able to work around this by calling setStyle() on the CSSStyleDeclaration that is governing the UITextField, or if you were just trying to save a value for later acces, you might be able to store the value as a property on the UITextField itself.

Technorati Tags: ,

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
Author: David Coletta Categories: Flex Tags:
  1. June 5th, 2007 at 03:31 | #1

    Very strange indeed, I had a look myself and couldn’t find anything either.
    Perhaps some components call setStyle() on a textfield that can either be a UITextField or a normal TextField?
    That’s the only theory I can come up with, but weird nevertheless..

  2. Taykalo Paul
    January 3rd, 2008 at 05:47 | #2

    Looks strange. I resolved this problem through setting parent styles, that UITextField is inheriting.

  3. Rob Barreca
    January 14th, 2008 at 14:30 | #3

    This was a super annoying “feature.” You can also use a UITextFormat and call setTextFormat() on the UITextField.

  4. February 1st, 2008 at 18:43 | #4

    It looks like the UITextField used through out the Flex Framework (TextArea, Button, etc…) sets the textField.styleName = this. Which sets the UITextField’s style object to the parent component, typically UIComponent of some sort. The UITextField then takes on any of the style object’s properties.

  1. No trackbacks yet.