parseCSS only works for text fields (See
http://livedocs.adobe.com/flex/3/langref/flash/text/StyleSheet.html)

You will need to parse the string yourself and apply styles as required.

One of the bigger problems are that some styles require strings, others
require numbers and some even require arrays.

I came up with the following code to demonstrate (You can extend it to
do whatever you want):

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute"
     creationComplete="onCreationComplete()">
     <mx:Script>
         <![CDATA[
             import mx.styles.StyleManager;

             private var styleString:String = "Button {cornerRadius: 9;
highlightAlphas: 0, 0; fillAlphas: 1, 1, 1, 1; fillColors: #6699ff,
#6699ff, #6699ff, #6699ff; color: #0033cc; textRollOverColor: #000000;
textSelectedColor: #000000; borderColor: #6699ff; themeColor: #ffffff;
fontSize: 12; fontWeight: normal; }";

             private function onCreationComplete():void
             {
                 var CSSArray:Array = styleString.split("{");
                 var CSSStyleDeclarationName:String =
CSSArray[0].replace(" ", "");

                 var stylesArray:Array = CSSArray[1].split(";");
                 for each(var currentStyle:String in stylesArray)
                 {
                     currentStyle = currentStyle.replace("}",
"").replace(" ", "");
                     if(currentStyle != null && currentStyle.length > 0)
                     {
                         var currentStyleName:String =
currentStyle.split(":")[0];
                         var currentStyleValue:String =
currentStyle.split(":")[1].replace(" ", "");
                         if(currentStyleName != null && currentStyleValue
!= null)
                         {
                             switch(currentStyleName)
                             {
                                 case "fillColors":
                                 case "fillAlphas":
                                 case "highlightAlphas":
                                    
StyleManager.getStyleDeclaration(CSSStyleDeclarationName).setStyle(curre\
ntStyleName, currentStyleValue.split(","));
                                 break;
                                 case "cornerRadius":
                                 case "fontSize":
                                    
StyleManager.getStyleDeclaration(CSSStyleDeclarationName).setStyle(curre\
ntStyleName, new Number(currentStyleValue));
                                 break;
                                 default:
                                    
StyleManager.getStyleDeclaration(CSSStyleDeclarationName).setStyle(curre\
ntStyleName, currentStyleValue);
                                 break;
                             }
                         }
                     }
                 }
             }
         ]]>
     </mx:Script>
     <mx:Button label="Test Button"/>
</mx:Application>



--- In [email protected], "MicC" <chigwel...@...> wrote:
>
> I am loading cssStyle text from server with a stored procedure and
> loading into a string:
>
> Button {
>     cornerRadius: 9;
>     highlightAlphas: 0, 0;
>     fillAlphas: 1, 1, 1, 1;
>     fillColors: #6699ff, #6699ff, #6699ff, #6699ff;
>     color: #0033cc;
>     textRollOverColor: #000000;
>     textSelectedColor: #000000;
>     borderColor: #6699ff;
>     themeColor: #ffffff;
>     fontSize: 12;
>     fontWeight: normal;
> }
>
> into cssString. I want to use this as the Application's StyleSheet
i.e.
>
>       <mx:Style source="contents of cssString"/>
>
> I tried
>
> this.styleName = cssString;
>
> and played with
>
> appStyle = new StyleSheet;
> appStyle.parseCSS(cssString);
>
> but a little knowledge is a dangerous thing :-) How do I get the style
> text to become the Application StyleSheet? TIA,
>
> Mic.
>

Reply via email to