That's because you're probably expecting Flash to wait between:
myMenuData.load() and trace(myTxt[3])
which it doesn't.
Loading data is asynchronous.
If you need something to happen when data has loaded, call another function
from within the onLoad event handler.
import mx.utils.Delegate;
var myMenuData:LoadVars;
var myTxt:Array;
var myFile:String = "../textFiles/menuLabels.txt";
function doWickedStuff():Void {
trace("Application ::: doWickedStuff");
trace(this.myTxt[3]);
}
function menuDataLoadHandler(success):Void {
trace("Application ::: menuDataLoadHandler");
if (success) {
this.myTxt = this.myMenuData.myVar.split(",");
trace(this.myTxt[3]);
this.doWickedStuff();
} else {
trace("Could not get data");
}
};
this.myMenuData = new LoadVars();
this.myMenuData.onLoad = Delegate.create(this, this.menuDataLoadHandler);
this.myMenuData.load(this.myFile);
regards,
Muzak
----- Original Message -----
From: "John Trentini" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, May 28, 2007 4:22 AM
Subject: [Flashcoders] loadVars not initialising first
> Hi there,
>
> (my second try at this, I was really hoping on some help with this one)
>
> I am sure this has an easy answer but i can't get my head around it.
> I have even put the code into an #include file to see if it would init the
> loadVars before anything else but, no luck..
>
> On Eric's early suggestion I have placed the .load aftert the onLoad function
> but that did not resolve my problem.
>
> I am getting data from an external text file and using the information
> tobuild a menu with the following:
> //
> var myMenuData = new LoadVars;
> var myTxt:Array = new Array();'
> //
> myFile = "../textFiles/menuLabels.txt";
> myMenuData.onLoad = function(success) {
> if (success) {
> trace("LoadVars loaded successfully: "+this.loaded); <==this one
> returns = true
> myTxt = this.myVar.split(",");
> trace(myTxt[3]); <==this trace returns the correct value
> } else {
> trace("Could not get the data");
> }
> };
> myMenuData.load(myFile);
> trace(myTxt[3]); <== this trace returns undefined
>
> I am unable to get the info out of the load function, what am i doing wrong?
> How can I make the info persistent?
>
> Thanks
> JohnT
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com