9 Replies Latest reply on Apr 10, 2007 7:08 AM by M._Dennis

    External CSS in Flex

    M. Huisman Level 1
      Hi,

      Is it possible to parse an external CSS file in flex?
      Somehow a few property's are used when I put my external stylesheet in Flex.

      Therefore it's quite difficult to control the application's colours and style by using the stylesheet of the HTML page where I intergrated the flex app in.

      Is there a workaround?
        • 1. Re: External CSS in Flex
          leotemp Level 1
          I dont understand your problem "Somehow a few property's are used when I put my external stylesheet in Flex." but i can give you a few tips about styles that might help.

          If you use external css files then use them like this:
          <mx:Style source="cssFolder/fileName.css"/>

          However its been my experience that the css implementation is bugy or works t differently of how one would think as the changes made in your css seems to only be applied on compiling of your app which isnt very useful in my opinion.

          What works best Ive found is to store your style information in xml form on the server and then parse it using a HTTPservice or something like that on your app Initalize event, then use the setStyle property to modify your apps looks, Example:

          For native flex controls:
          StyleManager.getStyleDeclaration("Application").setStyle("backgroundGradientColors", [0x00ff00, 0x0000ff]);
          StyleManager.getStyleDeclaration("Canvas").setStyle("borderColors", 0xff0000);
          That would set the application gradient to green and blue and all the applications canvas control's borders to red

          You can apply styles to individual controls like this:
          IdOfControl.setStyle("borderColor",0xff0000);
          The first parameter is the string of whatever style element you want to alter.
          • 2. Re: External CSS in Flex
            M. Huisman Level 1
            Ok, thanks, I got my answer out of your reply. It's practicly impossible to use an external CSS to feed the appearance of the flex application.

            • 3. Re: External CSS in Flex
              TIPLVinay Level 1

              Its possible to use the external CSS that is resposible for the appearance of your flex application (Does'nt matter it is within a html page of a free swf).
              Flex 2.0 provides CSS formatting for almost every component including entire Application .

              Why don't u use the same CSS for your HTML and Flex components...

              vicky
              • 4. Re: External CSS in Flex
                M. Huisman Level 1
                The main problem is that you have to compile the css file into the swf, this means that colours and appearance are only updated when recompiled.

                Therefore the whole CSS idea isn't usable within the Flex application.
                • 5. Re: External CSS in Flex
                  leotemp Level 1
                  Yeah, and thats really weird, i want to believe im just doing something wrong, would be nice to get an exact answer on if this if it is correct but every test ive done has made me come to the conclusion that css is only used at compile time, doh!
                  • 6. Re: External CSS in Flex
                    M. Huisman Level 1
                    I'm attending a Flex course next week, so this is one of the questions i'm going to ask. I'ts really weird that they implement an "cascading" stylesheet, and make it impossible to change at runtime.

                    There are some workarounds but they seem quite time-consuming e.g. creating an xml file with styles.
                    • 7. Re: External CSS in Flex
                      M._Dennis
                      quote:

                      Originally posted by: M. Huisman
                      I'm attending a Flex course next week, so this is one of the questions i'm going to ask.


                      Did you ever get an answer if it is possible to evaluate an external stylesheet at runtime?

                      • 8. Re: External CSS in Flex
                        M. Huisman Level 1
                        No, but in the 2.01 version it's implemented ;)
                        • 9. Re: External CSS in Flex
                          M._Dennis Level 1
                          I'm been using 2.01 and it doesn't appear to work