Load a CSS document and use that data to populate a StyleSheet object : StyleSheet « Development « Flash / Flex / ActionScript






Load a CSS document and use that data to populate a StyleSheet object

 
package {

  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.events.Event;
  import flash.text.TextFieldAutoSize;
  import flash.text.StyleSheet;
  import flash.net.URLLoader;
  import flash.net.URLRequest;

  public class CSSText extends Sprite {
      
    public function CSSText(  ) {
         var loader:URLLoader = new URLLoader(  );
         loader.addEventListener(Event.COMPLETE, onLoadCSS);
         var request:URLRequest = new URLRequest("styles.css");
         loader.load(request);
    }
    
    private function onLoadCSS(event:Event):void {
      var css:StyleSheet = new StyleSheet(  );
      css.parseCSS(URLLoader(event.target).data);
         var field:TextField = new TextField(  );
         field.autoSize = TextFieldAutoSize.LEFT;
         field.wordWrap = true;
         field.width = 200;
         addChild(field);
         field.styleSheet = css;
         field.htmlText = "<p><span class='emphasis'>Title</span> </p>";
    }
  }
}

        








Related examples in the same category

1.Text formatted with an external style sheet
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