tags:

views:

40

answers:

2

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
Thanks very much!
Paul
+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
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
Sorry I can't vote up cuz I don't have 15 points yet. :/
Paul
@Paul Never mind - glad to be of help :)
Amarghosh