PDA

View Full Version : making external variables useable



davec
September 28th, 2003, 02:11 PM
Why can I not access the data loaded from an external text file outside this function?

loadText = new loadVars();
loadText.load("movieList.txt");
//creating the loadVarsText function
loadText.onLoad = function() {
movieArray = this.movieList.split("/");
trace(_root.movieArray) //shows loaded data correctly
}

trace(_root.movieArray); //shows 'undefined'
the first trace within the function displays the loaded data correctly, the second trace just shows "undefined"

And why does the second trace show in the output window BEFORE the first as coded? i.e.

undefined
arr1,arr2,arr3

Thanks

andr.in
September 28th, 2003, 02:35 PM
try changing this:

movieArray = this.movieList.split("/");

into this:

var movieArray = this.movieList.split("/");

davec
September 28th, 2003, 02:57 PM
I've tried _global.movieArray, and moving the trace statement to a 2nd frame, which still gives 'undefined'.

If I place a button on the stage and tell it to trace(movieArray) on release, this works fine.

I can't understand how the trace works on a button, but not on a frame, or even a movieclip - transferring the whole code to clipEvent(load) or clipEvent(enterframe) unless I remove the stop(); statement from the second frame, then it displays 'undefined' once, then repeats the correct trace.

kode
September 28th, 2003, 03:32 PM
It's probably because the external file is not fully loaded when you call the trace action. :sigh:

andr.in
September 28th, 2003, 03:35 PM
Originally posted by kode
It's probably because the external file is not fully loaded when you call the trace action. :sigh:
Oh yeah.. why didn't I tihnk of that... :smirk:

davec
September 28th, 2003, 03:50 PM
That seems to be it. Put a trace in frame 2 and get 'undefined'.
Put the trace in frame 3 and it works.

Is it possible therefore to check if the whole file's loaded?

Thanks guys.

Dave

kode
September 28th, 2003, 03:57 PM
That's why you use the onLoad handler!! :P

Anyway, you could use the getBytesLoaded and getBytesTotal methods too.

davec
September 28th, 2003, 06:30 PM
Originally posted by kode
That's why you use the onLoad handler!! :P

Err, how then?

And if you use getBytesLoaded etc. then bytesLoaded for what?

loadText .getBytesTotal?

Cheers,

Dave

kode
September 28th, 2003, 07:10 PM
Using an onLoad handler...

var loadText = new LoadVars();
loadText.onLoad = function(success) {
if (success) {
// file loaded, you can use the variables now
}
};
loadText.load("movieList.txt");
Using the getBytesLoaded and getBytesTotal methods....

var loadText = new LoadVars();
loadText.load("movieList.txt");
this.onEnterFrame = function() {
var bloaded = loadText.getBytesLoaded();
var btotal = loadText.getBytesTotal();
if (bloaded>0 && bloaded == btotal) {
// file loaded, you can use the variables now
delete this.onEnterFrame;
}
};
Just tell me what you want to do and I'll do it for you; I have no time to explain it right now. :-\

davec
September 29th, 2003, 04:37 AM
Originally posted by kode

Just tell me what you want to do and I'll do it for you; I have no time to explain it right now. :-\ [/B]
Thanks, from what you've given me everything appears to be running A-OK now.

Much appreciated

Dave

kode
September 29th, 2003, 01:31 PM
Haha - Ok. Let us know if you have any problems. ;)