1 Reply Latest reply: Feb 17, 2009 11:19 AM by David_MB RSS

    How do I style XML text with CSS?

    David_MB Community Member
      How do I load a CSS stylesheet to format XML text that is loaded into the swf using AS3? The goal is to assign hyperlinks to a list of text. The only way I can find to do that is CSS formatted XML. However, there is very, very little information on how to load and apply CSS to XML text using AS3.

      Anyone know how to do this?
        • 1. Re: How do I style XML text with CSS?
          David_MB Community Member
          Nevermind I figured it out. But.......... just in case anyone wants to know this.................

          Here is the code that will apply a CSS stylesheet called "viewerData.css" to a text field called "list1" who's content is loaded from a XML file called "viewerData.xml" Basically this allows me to load a list of names into a text field with hyperlinks attached to them.

          --------------------------------

          var css:StyleSheet;
          var cssLoader:URLLoader = new URLLoader();
          cssLoader.load(new URLRequest("viewer_data/viewerData.css"));
          cssLoader.addEventListener(Event.COMPLETE, processCSS);
          function processCSS(e:Event):void {
          //trace("stuff");
          }


          var dataXML:XML;
          var XMLLoader:URLLoader = new URLLoader();
          XMLLoader.load(new URLRequest("viewer_data/viewerData.xml"));
          XMLLoader.addEventListener(Event.COMPLETE, processXML);
          function processXML(e:Event):void {
          dataXML = new XML(e.target.data);
          var linkData:String = dataXML.nameList;
          this.list1.styleSheet = css;
          this.list1.htmlText = linkData;

          }

          --------------------------------------------