PDA

View Full Version : loadvariables problem



jsrp
March 24th, 2004, 07:41 PM
Hi everybody,

In a flash movie, I load a list of file names using loadvariablesnum

This list goes into a variable called "filelist".

exemple value for filelist: movie1.swf,image4.jpeg,movie3.swf

Then I split this variable into an array and then with a loop, load each file into a target (they are called 1,2,3... in my main movie).

Well, if I do it in two "steps" it works. I mean I use a first button to load the variables then a second one to split the list and so on.

If I put the whole script into one button, same event, it doesn't work (it's like if my filelist was still empty)

If I put the first part into the press event and the second into the release event, it works again.

The problem is that I don't want to use buttons. I want to put the whole script in a frame.
I tried to put the first part (loading the variables) into a first frame and the second part (splitting my array and loading movies) in the next one, but it does'nt work. The second part seems to ignore that the variables have been loaded...

Any explanation ? Any solution ?

Thanks

iroqfox
March 24th, 2004, 08:11 PM
You should post the parts of your code to give an idea of where the problem may be. I am working on something very close to this and may have a solution.

jsrp
March 25th, 2004, 12:59 AM
OK

The first part of the code:

loadVariablesNum(artist_id, 0);

where artist_id is a variable containing the name of a text file.
The content of this text file is eg:

artist_name=John Smith&elementslist=mov1.swf,img30.jpg,img31.jpg

so 2 variables are filled: artist_name and elementslist

The second part of the code:

myarray = elementslist.split(",");
result = myarray.length;
for (i=1; i<=result; i++) {
myarray[i-1] = "profiles/" add artist_id add "/" add myarray[i-1];
eval(i).loadMovie(myarray[i-1]);
}

so the files are loaded into instances called 1,2,3...

virusescu
March 25th, 2004, 04:39 AM
I think it doesn't work in only one step because the variables don't have time to load
Try a trace on one variable before making the array and my guess is you'll get undefined.

You should try using the loadVars object to have control over the loading time. This would give you access to an myLoadVars.onLoad() event.

Or simply make an if in the second part of your code. something like

if (artist_name){
second part of your code
}

Hope it helps.

Hey :) this is my first post :P Cheers to all

iroqfox
March 25th, 2004, 09:26 AM
Try something like this to load your vari's.

myVars = new LoadVars();
myVars.load("http://domainname.com/file.php");
myVars.onLoad = function(success) {
trace("waiting for data....");
if(success) {
trace (myVars.artist_name);
trace (myVars.elementslist);
} else {
trace ("no returned data");
}
}

Hope it helps. :cons:

jsrp
March 25th, 2004, 09:57 AM
Thanks. I had just found a solution by myself. I think it's a similar idea

loadVariablesNum(artist_id, 0);

_root.onData = function () {
myarray = elementslist.split(",");
result = myarray.length;
for (i=1; i<=result; i++) {
myarray[i-1] = "profiles/" add artist_id add "/" add myarray[i-1];
eval(i).loadMovie(myarray[i-1]);
}
};

I suppose that the onData event is generated once the variables are really loaded.

I will try yours too.