-
Notifications
You must be signed in to change notification settings - Fork 4
StyleManager (CSS)
The StyleManager class is what is required if you want to use CSS with your components. A StyleManager instance is supplied to the UIElement's styleManager property. By then setting the styleName property for the UIElement, a style will be applied when the setStyle() method is invoked on the UIElement.
###Steps
- Create a styleSheet
- Create a StyleManager
- Declare a StyleManager
- Create a UIElement
- Style UIElement
The first step is to create a blank stylesheet and place it into a directory. For this example I have created a stylesheet which is located in {project-root}/resource/embed/css/.
A StyleManager is class where resources are embedded into the flash file as Class files. Create a class which extends StyleManager and use the embed tag and embed the stylesheet as shown below. The embed tag needs to be associated with a class so ensure you create a variable after the embed tag. In the main function the stylesheet class needs to be parsed, the ' parseCSSByteArray' function is called with the stylesheet class as the parameter, this will then parse the css.
public class LatinStyle extends StyleManager
{
[Embed( source="/../resource/embed/css/KodakStyle.css", mimeType="application/octet-stream")]
private var LatinCSS:Class;
public function LatinStyle()
{
super();
parseCSSByteArray( LatinCSS );
}
}
To be able to obtain the css data the styleManager class must be declared. In the MVC approach a new styleManager is stored into the model as shown below.
styleManager = new KodakStyle();
Below is an example of how to declare a UIElement.
var _backButton:UIElement = new UIElement();
Now we need to provide the UIElement with a styleManager so that the UIElement can obtain the styleSheet.
_backButton.styleManager=_model.styleManager;
In the styleSheet create a new style and give it a name called “.questionBackButton ” and add the height and width as below.
CSS .questionBackButton{width:100;height:30;}
Provide the UIElement with the styleName as shown below and then build, setStyle,arrange and addChild.
_backButton.styleName="questionBackButton";
_backButton.build();
_backButton.setStyle();
_backButton.arrange();
addChild(_backButton);