Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had similar problem but more precisely i want the completely avoid the compilation because my application is wrapper by ActiveX used by a custom exe file and i let the software distributor to customize their skin.</p> <p>In practice we put the &lt;fx:Style&gt; outside the application. To avoid low level parsing on the string we had transformed the Style Sheet in an XML:</p> <pre><code>&lt;styles&gt; &lt;namespace name="myNs" value="com.myComponent"&gt; &lt;declaration selector="myNS|Button#myselector:over #mysubselector"&gt; color:#ffffff; font-size:bold &lt;/declaration&gt; ... other styles &lt;/styles&gt; </code></pre> <p>Beside the security considerations about let the user know your components you can load the XML and create a CSSStydeclaration. </p> <p>Splitting and parsing only the selector let you create a series of CSSCondition and CSSSelector to add to your CSSStyleDeclaration. To parse the selector we use a little loop which search "#",":" and "." and split the string mantaining the sequence of the found CSS conditions.</p> <pre><code>var selectors:Array = []; // first selector var conditions:Array = [ new CSSCondition(CSSConditionKind.ID, 'myselector'); new CSSCondition(CSSConditionKind.PSEUDO, 'over'); ]; // here you have to find and expand the namespace ancestor:CSSSelector = new CSSSelector('com.myComponent.Button', conditions); selectors.push(selector); // second selector var conditions:Array = [ new CSSCondition(CSSConditionKind.ID, 'mysubselector'); ]; selector:CSSSelector = new CSSSelector('', conditions, ancestor); selectors.push(selector); // Empty style declaration new CSSStyleDeclaration(selectors, styleManager, false); </code></pre> <p>Then you can parse CSS properties by parseCSS() with the function created by @sixtyfootersdude, but using a fake selector:</p> <pre><code>var myCSS:String = "#fake " + "{" + cssTextReadedFromXML + "}"; var style:StyleSheet = new StyleSheet(); sheet.parseCSS(myCSS); // here you have your parsed properties var list:Object = sheet.getStyle('#fake'); </code></pre> <p>Then you can add the properties to the CSSStyleDeclaration and apply them by the setStyle method and apply the declaration as in your example.</p> <p>Less or more is how I've tryed to resolve this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload