tags:

views:

471

answers:

2

I inherited a custom component from TextField. The component needs to know when any of its styles got changed at runtime via setStyle. How would I do that? It's probably obvious but I couldn't find an event or appropriate method to override.

+2  A: 

If you want the text field to play nicely with containers and other components in Flex you may want to wrap it in a UIComponent, or have the subclass implement the IUIComponent and IStyleClient or ISimpleStyleClient interfaces (which UIComponent implements). If you do the component will work with Flex' style system and every time a style changes a method called styleChanged` will be called:

public function styleChanged(styleProp:String):void

See http://livedocs.adobe.com/flex/3/langref/mx/core/UIComponent.html#styleChanged()

Theo
Ah. Yeah. Thanks for taking the time to post the better answer. +1
Ross Henderson
_Especially_ since TextField doesn't inherit from UIComponent...
Ross Henderson
Thanks Theo. Great info! Unfortunately I don't have enough reputation points yet to vote you up.
Stefan
Stefan: you should be able to change the accepted answer.
Theo
A: 

Hello

styleChanged () method

public function styleChanged(styleProp:String):void

Detects changes to style properties. When any style property is set, Flex calls the styleChanged() method, passing to it the name of the style being set.

This is an advanced method that you might override when creating a subclass of UIComponent. When you create a custom component, you can override the styleChanged() method to check the style name passed to it, and handle the change accordingly. This lets you override the default behavior of an existing style, or add your own custom style properties.

If you handle the style property, your override of the styleChanged() method should call the invalidateDisplayList() method to cause Flex to execute the component's updateDisplayList() method at the next screen update.

Parameters styleProp:String — The name of the style property, or null if all styles for this component have changed.

Adrian, http://www.timeister.com

Adrian Pirvulescu
rhtx, Theo, thanks for your input. I decided to set this one to the correct answer as it does what I expected although Theo's input on text fields is very valuable.
Stefan
"Parameters styleProp:String — The name of the style property, or null if all styles for this component have changed."That explains why styleProp is always null on this comp I'm making ;)Thanks
Jonathan Dumaine