1 Reply Latest reply on Apr 15, 2009 11:33 AM by Handycam

    how do I apply CSS styles to HTML in an mx:Text element?

      Hello,

       

      I have an MXML file with an <mx:Text id="msg"> element defined.

       

      I've also got an external stylesheet which I'm accessing like this:

       

      private function grabStyles():void {
          var cssRequest:URLRequest = new URLRequest("/widget/assets/css/baseHtmlStyles.css");

       

          var cssLoader:URLLoader = new URLLoader();
          cssLoader.addEventListener(Event.COMPLETE, applyStyles);
          cssLoader.load(cssRequest);
      }

       

      private function applyStyles(evt:Event):void {
          var css:StyleSheet = new StyleSheet();
          css.parseCSS(URLLoader(evt.target).data);
          msg.styleSheet = css; // this is where it fails
          msg.htmlText = '<p>This is a <b>test</b></p>';
      }

       

      The problem is with applying the styleSheet to the <mx:Text> element.  I've seen nuermous examples where a stylesheet is applied to a textField object via the textField object's styleSheet property.  The Text element, however, doesn't seem to have a styleSheet property -- I get this error on compile: "Attempted access of inaccessible property styleSheet through a reference with static type mx.controls:Text."

       

      Can anyone point me in the right direction?

       

      Thanks!

        • 1. Re: how do I apply CSS styles to HTML in an mx:Text element?
          Handycam Level 1

          I don't know if this will be any help, but when I used loaded xml in an html text field, I looped through it and output html, like this:

           

          private function processFavorites() : void {

          var _faveList : String = "<ul>";

          for each (var item:XML in app._presets) {

          _faveList += "<li>" + item + "<br><br>";

          }

          _faveList += "</ul>"

          favorites.htmlText = _faveList;

          }

           

          Where "item" is the node in the xml that I wanted to make into a LI.  Sloppy, perhaps but maybe you could put your css tagging in that way?