This it’s a clean example about how to add a CSS style to a component in Flex.
We need to create the CSS file (style.css) and add a custom style:
.myStyle { font-size: 20px; color: #cc0000; }
Make a new Flex project and in the defalul MXML aplication file add this code:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" > <!--// Here we call our CSS file into the project --> <mx:Style source="style.css"/> <!--// This is a simple Text component --> <mx:Text x="50" y="50" width="300" height="100" text="This is a simple Text component with style set up in a CSS file" styleName="myStyle" /> </mx:Application>
Also we can use ActionScript to add styles to components:
var _tmpLabel:Label = new Label(); _tmpLabel.text = "Here you can add your text."; _tmpLabel.setActualSize(300,100); _tmpLabel.styleName = "myStyle";
Tags: ActionScript, component, css, flex, MXML, style
This post was written by Stelian Crisan
Views: 2524



















Hi all,
I facing a problem in applying CSS in the custom component.
1. I am having the css file.
2. Created the component in action script.
3. Now I need to apply the css for the created custom components with the external css file.
How to apply the css to the components.
Please let me know
Thanks and Regards
Balaji