Posted By

chrisaiv on 01/03/08


Tagged

as3


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

abdsign
visuallyspun
jmontanino
oamaxa
THEPWN3R
enajenkins
TrentSkunk
tspitzr


AS3: Load external .txt and .css


 / Published in: ActionScript 3
 

Here is an intermediate example of how to load an external .txt file and apply an external .css

  1. /***************************************
  2. Initialize Variables
  3. ***************************************/
  4. var tf:TextField = new TextField();
  5. tf.width = stage.stageWidth;
  6. tf.height = stage.stageHeight;
  7. addChild(tf);
  8.  
  9. var wordList:Array = new Array();
  10.  
  11. var textLoader:URLLoader = new URLLoader();
  12. textLoader.addEventListener(Event.COMPLETE, textLoaded);
  13.  
  14. var cssLoader:URLLoader = new URLLoader();
  15. var css:StyleSheet = new StyleSheet();
  16.  
  17.  
  18. /***************************************
  19. Parse Text + Apply External CSS
  20. ***************************************/
  21. function cssLoaded(e:Event):void{
  22. css.parseCSS(e.target.data);
  23. tf.styleSheet = css;
  24.  
  25. for(var i:int = 0; i < wordList.length; i++){
  26. tf.htmlText += "<h4>" + wordList[i] + "</h4>";
  27. }
  28. }
  29. function textLoaded(e:Event):void{
  30. wordList = e.target.data.split("\n");
  31. cssLoader.load(new URLRequest("http://www.channelone.com/css/flash_block.css"));
  32. cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
  33. }
  34.  
  35. textLoader.load(new URLRequest("http://www.channelone.com/fun/swf_band_name_txt.txt"));

Report this snippet  

You need to login to post a comment.