Customizing the Look & Feel of a Flex Application
Posted on October 20, 2010 | Comments Off on Customizing the Look & Feel of a Flex Application
Applying Styles
Flex styles are based on the web standard CSS (Cascading Style Sheets). There are several levels a style may be applied at:
You may specify a single style on a particular component, use a CSS Class selector to set several styles together or use a type selector to specify that all components of a particular type should use the provided style values.
A style may be applied to a component directly in its MXML definition by adding the style name as a property and specifying it’s value such as
to display a bold label. The setStyle() method can also be used to achieve the same effect – mLabel.setStyle(“fontWeight”,”bold”)
Note that when using setStyle() and specifying colors, the prefix 0x is used to indicate a hexadecimal value (and quotes are not required around them). When specified in a tag or CSS attribute, the prefix # may be used instead.
setStyle() is an expensive run time operation so it’s use should be limited.
The Flex language reference will tell you what styles are available for a particular component and will also specify CSS inheritance. If yes, this indicates that if the parent of this component has a value specified for the style, the child component will use the same value unless it has its own value specified. (For example, if you have a Label in a HBox, it will inherit the HBox color (text color) unless it has its own color value set.
Setting Styles buy levitra online with CSS
The
.myStyle{
color:#FF00FF
selectionColor:#00FF00
}
You may also use CSS type selectors which define a set of styles to be applied to all instances of a component type.
ComboBox{
color:#FF00FF
selectionColor:#00FF00
}
Both myBox1 and myBox2 will have the same color and selectionColor.
Note that Flex does not support ID selectors.
Flex will support traditional CSS style formatting for the properties it supports (ie all lowercase with hyphen to separate words such as background-color) within a Style tag but for attributes that are specific to Flex and all attributes outside of Style tags, the camel case form of the name is required (eg backgroundColor). This is because the hyphen is not a valid character for XML attributes and MXML tags must be valid XML.
CSS properties that require multiple values are specified using a comma separated list of values. It’s important to note that those properties must have at least two values (even if they are the same) to avoid an error as a single value will not map correctly to an array.
You may also use mx:Style to specify an external CSS file to compile into the app using the source attribute. This should always be placed within the file containing the Application tag – setting how do i buy viagra online | buy cialis canadian | cheap levitra generic style imports in child documents can give rise to unexpected results.
Run Time CSS
The disadvantage of specifying an external file to load in this way is that it is compiled into the application and thus any changes to the CSS require the app to be re-compiled. By loading the CSS at run time, this situation can be avoided and different CSS files could be loaded depending on data provided so if for example, you had a collage sports app, you could brand your app with the team colors of where your users login from.
Flex can’t deal directly with a CSS file but the compiler can convert that to a SWF which it can use. To do this in FlashDevelop, right click the CSS file, select “always compile”, go to project properties and specify the output filename you want to use and compile (don’t forget to switch back to your regular app when you’re done).
Once you have your CSS SWF, just use
StyleManager.loadStyleDeclarations(“myCSSFile.swf”)
to load it. A second optional parameter is update a boolean (which defaults to true). If set, this forces an update of all the styles in the application. If you’re loading several CSS SWF files, you should set this to false for all but the last one to reduce the overhead of this operation.
you may also use
StyleManager.unloadStyleDeclarations(“myCSSFile.swf”)
to unload a CSS. This also has an optional update parameter with the same effect.
It’s possible to have several levels of style in play, the rule being that if a style is defined in multiple places, Order Generic Amoxil Online without Prescription the last one loaded is the one used.
Incoming search terms:
- steppedlnl (1)
Tags: loadStyleDeclarations | setStyle() | StyleManager | styleName | unloadStyleDeclarations