Flex and runtime CSS

28 04 2008

Runtime CSS is quite easy in Flex.

Essentially you need to right click the CSS file in Flex Builder and select the option Compile CSS to SWF.

Then you use mx.styles.StyleManager.loadStyleDeclarations(URL:String,update:Boolean = true) to import the SWF at runtime.

The reason you might want to set the “update” parameter to false is if you’re loading multiple SWFs at a time and would rather apply them as a group (avoiding unneccessary processing).

NOTE:

  1. If you want to override styles set on a tag itself – such as the Application, make sure the tag(s) in question don’t have the same styles set in the MXML, because like HTML & CSS, styles on a tag itself will override any imported CSS file.
Advertisements