Difficulties loading and formatting external txt files -- Solved!
I have been a quiet lurker on these forums for the better part of a year now, searching through old posts for the answers to problems that I have encountered. Recently, though, loading and formatting text from external .txt files has caused me so much difficulty that, even given the numerous other questions that are similar to this that have been addressed, I still find myself without answer and, in my frustration, have actually created an account on flashkit at last.
I use Flash MX 2004 and I want to create dynamic text boxes at runtime, populate them with text from an external text file, and then format them to suit the style of my flash page. This sounded to me, sometime last week when the idea occured to me, a perhaps complex idea, but an elegently customizable one and worth the effort.
This, of course, has not proved as easy as I would hope. My issue is this: when I attempt to load a text file saved in the local directory, it does indeed successfully load, but I am inable to reference it after it does. Thus:
code:
_root.skemaVars = new LoadVars();
_root.skemaVars.load("littletxt.txt");
_root.skemaVars.onLoad = function(success) {
if(success) {
tekst = this.tekst;
trace(_root.skemaVars.tekst);
} else {
trace("File not loaded. Try again, dummy!");
} trace(_root.skemaVars.tekst);
}
trace(_root.skemaVars.tekst);
This code is essentially a direct copy of code posted by "gobbles" about a month ago, but does not differ substantially from any one of a dozen posts of its kind that I have read.
The file "littletxt.txt" reads : tekst="How I wish that this would work."
It is apparent that, in attempt to debug this problem of mine, I have added numerous trace statements to try and spot where things break down. When I run the program, I receive the following three statements in the "Output" window:
undefined
"How I wish that this would work."
"How I wish that this would work."
I do not know whether my inability to reference the variable from outside the curly brackets that compose the LoadVars stems from a lack of understanding of dot syntax or if I am doing something else wrong, but the fact is that I am at my wits end.
Sorry abuot the long nature of this post; any help in this matter would be very much appreciated.
Pacem!
-- T