Formatting text with an externally loaded style sheet : URLRequest « Network « Flash / Flex / ActionScript






Formatting text with an externally loaded 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>";
    }
  }
}

        








Related examples in the same category

1.Loading XML Data from External Sources
2.Add URLrequest to Loader
3.Loading XML Data: Event.COMPLETE listener
4.Loading a bitmap at runtime
5.Starting the load operation
6.Adding an asset to the display list
7.Use FileReference to download file from a URL