I read text file name/values into a swf, but cannot seem to get at those vars outside of the scope of the .onload portion of my script. _global seems to have no effect. What am I missing here?
Example:
data_file="../localHD_data.txt";
The contents of this simple little text file look like this:
&book_title=Scrambled Eggs&
&ch1_title=Introduction&
&ch2_title=Preparing Eggs&
&ch3_title=Cooking the Eggs&
After reading my question, take note that I ALSO have referenced a _global var in this little script, as it always does display correctly and may shed some light on my problem? here is my script example:
_global.ISBN="sometext here";
function getTextFileData() {
textfile_data=new LoadVars();
textfile_data.onLoad=function() {
book_title=textfile_data['book_title'];
chapter1_title=textfile_data['ch1_title'];
chapter2_title=textfile_data['ch2_title'];
chapter3_title=textfile_data['ch3_title'];
isbn_number=ISBN;
//alert_as("book_title :"+book_title+"\r"+"chapter1_title :"+chapter1_title+"\r"+"chapter2_title :"+chapter2_title+"\r"+"chapter3_title :"+chapter3_title+"\r"+"ISBN# :"+isbn_number+"\r");
}
textfile_data.load(data_file);
//alert_as("book_title :"+book_title+"\r"+"chapter1_title :"+chapter1_title+"\r"+"chapter2_title :"+chapter2_title+"\r"+"chapter3_title :"+chapter3_title+"\r"+"ISBN# :"+isbn_number+"\r");
}
getTextFileData();
When I run this function, I can see the variables if I uncomment the first “alert();” there. Note that the value of isbn_number also displays, ok?"
However, if I comment it back out and uncomment the SECOND “alert();” there, only the value of isbn_number displays in my alert. It is as if the vars/values that are captured and defined WITHIN the .onload portion of the script are “trapped in scope” inside of that .onload function.
How can I reference these vars/values “outside of” my getTextFileData function.
NOTE: I have tried the following but it has no discernable different/improvement:
function getTextFileData() {
textfile_data=new LoadVars();
textfile_data.onLoad=function() {
_global.book_title=textfile_data['book_title'];
_global.chapter1_title=textfile_data['ch1_title'];
_global.chapter2_title=textfile_data['ch2_title'];
_global.chapter3_title=textfile_data['ch3_title'];
_global.isbn_number=ISBN;
//alert_as("book_title :"+book_title+"\r"+"chapter1_title :"+chapter1_title+"\r"+"chapter2_title :"+chapter2_title+"\r"+"chapter3_title :"+chapter3_title+"\r"+"ISBN# :"+isbn_number+"\r");
}
textfile_data.load(data_file);
//alert_as("book_title :"+book_title+"\r"+"chapter1_title :"+chapter1_title+"\r"+"chapter2_title :"+chapter2_title+"\r"+"chapter3_title :"+chapter3_title+"\r"+"ISBN# :"+isbn_number+"\r");
}
getTextFileData();
Frustrated with this scoping issue,
good grief! Thank you in advance for your time in considering my dilemma here. We are all busy, I know.
Ian