Apply CSS to HTML in Flash ActionScript 3.0 - Step 6: Loading the TEXT file
Posted by : FireCode on Sep 03, 2010
We begin by defining our loader for the text at the begining of our code. Once we've loaded the text file, we apply the CSS style to our text field on the stage. Doing so we can now add the content of the loaded text to the text field using the htmlText propriety of the text fields.
var _style:StyleSheet = new StyleSheet();
var _css:URLLoader = new URLLoader();
_css.load(new URLRequest("style.css"));
_css.addEventListener(Event.COMPLETE, StyleLoaded, false, 0, true);
var _text:URLLoader = new URLLoader();
_text.addEventListener(Event.COMPLETE, TextComplete, false, 0, true);
function StyleLoaded($e:Event):void
{
_css.removeEventListener(Event.COMPLETE, StyleLoaded);
_style.parseCSS(_css.data);
_text.load(new URLRequest("text.txt"));
}
function TextComplete($e:Event):void
{
_text.removeEventListener(Event.COMPLETE, TextComplete);
_textField.styleSheet = _style;
_textField.htmlText = _text.data;
}

no comment
Add comment