I’m starting to learn classes and I’m doing a class that loads a textfile with a variable, using loadVars, followed by pure html text, then it applies css to the html text and displays it in a target textfield…
I’m still new at this as I said so the code is very rough. I’ve worked out all the little kinks up to now… I’m stuck at one thing:
When the text loads, the “loadVars.onLoad = function” is supposed to fire the css function that applies the stylesheet to the text, but I simply can’t get the function to run…
Is it impossible to call a private function from another private function in a class block?
code:
class LoadHtmlText {
/**
* LoadHtmlText Constructor
*
* @param url The path to the textfile
* @param textFileVar The variable name in the textfile
* @param target The TextField instance
* that will display the text
* @param CSSurl The path to a CSS file
*/
private var loadText:LoadVars;
private var cssStyle:TextField.StyleSheet;
public function LoadHtmlText(url:String, textFileVar, target:TextField, CSSurl:String) {
newLoadVars();
newStyleObject();
textLoader(url, target, CSSurl, textFileVar);
//CSSLoader(CSSurl, target);
}
// newLoadVars
private function newLoadVars() {
loadText = new LoadVars();
}
private function newStyleObject() {
cssStyle = new TextField.StyleSheet();
}
// load some text
private function textLoader(url:String, target:TextField, CSSurl:String, textFileVar) {
loadText.load(url);
// check if loaded:
loadText.onLoad = function(success) {
if (success)
{
trace("text loaded");
CSSLoader(CSSurl, target, textFileVar);
}
else
{
trace("text not loaded");
}
};
}
// load a css
private function CSSLoader(CSSurl:String, target:TextField, textFileVar) {
trace("css function ran");
cssStyle.load(CSSurl);
cssStyle.onLoad = function(success) {
if (success)
{
trace("css loaded");
target.html = true;
target.multiline = true;
target.wordWrap = true;
target.styleSheet = cssStyle;
target.htmlText = loadText[textFileVar];
trace(this);
}
else
{
trace("css not loaded");
}
};
//return target;
}
}
Any help is highly appreciated!