FlashComGuru Home Imediasee Influxis Uvault Akamai
                                                                                       Forum Index | Active Topics | Register
                                                                                                          List Overview | List Archives
                                                                                                                           About this site | Advertise
 

home

Adobe AIR (8)
Applications (32)
Books & Training (9)
Collaboration (8)
Components (6)
Events (49)
Flash Player (8)
Flex (28)
FMS (67)
General (107)
Hosting (5)
Jobs (13)
Off topic (31)
Press Releases (7)
Site Check (7)
Tools (39)
Videos & Players (50)

Flash On the Beach

Alltop, all the cool kids (and me)

 
Is it possible do set styles via CSS at runtime inside a Flex app? I read about this method on Ted's blog but it appears that I still need to set up and compile the stylesheet upfront, which means I need to know the colors etc that I want to use in the future... To me that seems to be a designtime style, not a runtime one.
Example in hand: I need to build a Flex app that is configurable in appearance via a CMS. I figured that it would be great to use an external stylesheet for this and generate that from the CMS. But reading Ted's post I now realize that Flex CSS styles are compiled into the SWF, not loaded and somehow processed at runtime. Am I correct here? I assume that's the case because when I remove the CSS folder from my bin directory I still see my styles, so the CSS is not external after all...!? Sorry but I assumed it was, at least that's how I expetced it to work.

So what do I do? Do I need to save my styles in XML for example, load the XML at startup and then set colors? I'd call that a step in the wrong direction (the German's have a saying for that which goes somewhat like: 'from behind through the chest into the eye').
Or is this a job for FDS (in which case it's overkill as the rest of the app won't need it). Thoughts? I am sure there are many use cases for stylising Flex apps without having to compile CSS SWFs or even the entire app itself...

Comments
[Add Comment]
You might want to look at this page.
http://www.scalenine.com/samples/themeSwapper/them...
# Posted By Dave | 1/26/07 5:04 PM
thanks, but that loads a SWF'ed CSS.
# Posted By Stefan | 1/26/07 5:08 PM
I noticed that the StyleSheet.load() method has been removed in AS 3.0. I had a library of classes to do this in Flash 7 and 8 and I have been looking at this issue in Flex but the type of development I do now doesn't require runtime styles so it is sitting on the back burner. My thoughts are that it is possible to load a stylesheet with the URLReqeust class and then use the StyleSheet, StyleManager, or CSSStyleDeclaration classes to create the styles in your swf at runtime. I haven't had time to explore this but I can see it being possible.
# Posted By Andrew | 1/26/07 8:41 PM
thaks Andrew, this sounds like something worth exploring...
Do let me know if you come across anything.
# Posted By Stefan | 1/26/07 8:56 PM
I believe runtime css is posible in Flex 2.01 maybe u should update to that version.
The details are here:
http://www.adobe.com/devnet/logged_in/mchotin_flex...
# Posted By Nihil | 1/26/07 10:36 PM
The reason you must load styles through an external SWF at runtime is because you can change any style, including graphical skins. You can't include something like that with a simple text CSS file. Adobe needed to make sure you could alter anything!

In your case, you seem to only care about changing colors at runtime. A few months back, I was able to write a class to parse stylesheets (with a little RegEx). Unfortunately, I cannot share my code because it belongs to my former employer, but it only took me about a day to get it working. You just need to get the styles from the file and their new values and use StyleManager, CSSStyleDeclaration, or the setStyle function to get things going.
# Posted By Josh Tynjala | 1/26/07 10:51 PM
thanks Josh, I'll give that approach a try.
# Posted By Stefan | 1/27/07 9:21 AM
Flex 2.0.1 does support Runtime CSS.
# Posted By Renaun Erickson | 2/7/07 6:48 PM
hi Renaun,
but look at how those CSS SWF files are generarated... they must be present at compile time. Or are you saying I can change a CSS text file and flex will reflect those changes everytime the swf is run?
# Posted By Stefan | 2/7/07 9:28 PM
Did you ever figure out how to do this ?
# Posted By Jason | 2/26/07 12:57 AM
no not really... but I haven't had much time to try yet
# Posted By Stefan | 2/26/07 9:24 AM
Check out this CSSLoader of a developer-friend of mine:
http://www.rubenswieringa.com/blog/cssloader
# Posted By Maikel Sibbald | 3/19/07 12:18 PM