I'd like to load CSS stylesheets from a URL and apply them to my Flex 3 application at runtime. Is it possible?
+1
A:
You cannot load an uncompiled CSS file into your Flex application at run time. You must compile it into a SWF file before loading it. - Adobe Flex 3 Docs
You can load style sheets (compiled) using the Style Manager.
For the full run-down : Loading style sheets at run time
phwd
2010-05-26 05:13:14
Thanks very much!
Paul
2010-05-26 05:37:32
+1
A:
You can load css files at runtime to style the text in a TextField
.
var loader:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest("style.css");
loader.load(req);
loader.addEventListener(Event.COMPLETE, completeHandler);
private function completeHandler(e:Event):void
{
var css:StyleSheet = new StyleSheet();
css.parseCSS(e.target.data);
yourTextField.styleSheet = css;
}
As for styling controls, I'm afraid you can't load a text file at run time. May be you can parse it using the StyleSheet
class - check out the styleNames
array and the getStyle
method.
Amarghosh
2010-05-26 05:33:11
Thanks alot. We're going to put styling on the backburner for now until we have time to do the compilation ourselves and/or investigate your suggestion of parsing with StyleSheet class.
Paul
2010-05-26 05:41:53