Text formatted with an external style sheet : StyleSheet « Development « Flash / Flex / ActionScript






Text formatted with an external style sheet

 
package {
  import flash.display.*;
  import flash.text.*;
  import flash.events.*;
  import flash.net.*;

  public class Main extends Sprite {
    public function Main (  ) {
      var urlLoader:URLLoader = new URLLoader(  );
      urlLoader.addEventListener(Event.COMPLETE, completeListener);
      urlLoader.load(new URLRequest("styles.css"));
    }

    private function completeListener (e:Event):void {
      var styleSheet:StyleSheet = new StyleSheet(  );
      styleSheet.parseCSS(e.target.data);

      var t:TextField = new TextField(  );
      t.width = 200;
      t.styleSheet = styleSheet;
      t.htmlText = "<p>ActionScript is fun!</p>";

      addChild(t);
    }
  }
}

        








Related examples in the same category

1.Load a CSS document and use that data to populate a StyleSheet object
2.Use CSS to in TextField
3.Formatting text with a programmatically created style sheet
4.Formatting applied to a specific class of paragraph
5.Set the font with CSS