This is a problem that I should have tackled long ago.
I’m loading dynamic htmlText into into a text box like this:
import TextField.StyleSheet;
// Load the css file, then the text file (containing some html)
var cssUrl :String = "fonts.css";
var htmlTextUrl:String = "news_1.txt";
var css:StyleSheet;
// Deal with a IE/Firefox inconsistency.
function fixUrl(url:String):String
{
var rootUrl:String = _root._url;
var iLastSlash:Number = rootUrl.lastIndexOf('/');
if (iLastSlash > 0){
rootUrl = rootUrl.substr(0,iLastSlash);
}
return rootUrl + "/" + url;
}
function loadCSS():Void
{
css = new StyleSheet();
css.onLoad = function(bSuccess:Boolean):Void
{
if (bSuccess){
loadHtmlText();
}
}
css.load(fixUrl(cssUrl));
}
function loadHtmlText():Void
{
// Use xml to load a text file.
var xml:XML = new XML();
xml.onData = function(txt:String):Void {
displayText(txt);
};
xml.load(fixUrl(htmlTextUrl));
}
function displayText(htmlText:String):Void
{
var t:TextField = field_txt;
t.html = true;
t.styleSheet = css;
t.embedFonts = true;
t.autoSize = true;
t.htmlText = htmlText;
}
loadCSS();
Problem is, there’s a gap between the moment the text box is displayed and the moment the text inside it loads and is displayed, resulting in a sloppy presentation… :
Can anyone point out a good way to modify the code I’m using and preload the .txt file?