Tutorial :Flex: Apply styles through composition?



Question:

I have a component based on HBox that has multiple labels in it. I want to be able to set all the style properties, things like fontSize, fontWeight, color, etc. on my component and have them applied to all the Labels contained by it. Whats the best approach for this? I tried to have my component implement Label but there is no Label interface.

Thanks.

P.S. Wasn't sure what would be a good title for this question so feel free to edit it if you have something better.


Solution:1

Two options I can think of:

  1. You could provide a default stylesheet (default.css) with your component and have use custom styles for Label.fontSize, Label.fontWeight, etc which would propagate throughout.
  2. You could extend Label to create a custom component and define default styles within that. Then use your custom Label within your custom component.

Check out this documentation for more info:
http://livedocs.adobe.com/flex/3/html/help.html?content=ascomponents_8.html


Solution:2

I didn't realize this but you can already just set all those properties on the HBox and the labels inside it inherit them. :)


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »