Dynamically loading Images set as vars in a text file

Hi,

I am new to Flash and was hoping someone could help me.

I have numerous file names stored as vars in a text file e.g.

f1p0=1_short_blue_left.swf&f2p0=0_medium_blue_left.swf&f3p0=3_medium_yellow_left…

So in the main timeline I will have an action that loads the vars from the textfile.

I have to load these movie files(that will contain only a graphic) into specific postions in a movie. I was hoping to mark the positions with var names i.e. I will have a path p0 and the first image will be placed at f1p0 the second image will be placed at f2p0 (somewhere else on the path) etc.

Can I mark the position with var name so that it will be loaded with the movie file assigned in the textfile?

If anyone can help or give alternative approaches I would really appreciate it.

Thanks

Well… I’ve never heard of doing that… but you never know.

If you’re going to load outside swf’s into your movie you have to load them into a movie clip or a level. You can’t really do exact possitioning with levels, so you’re only resort is to load the swf’s into movie clips on the stage.

Do you know what I’m talking about or does it sound like Greek?

(I only ask because you say you’re new to Flash, but already you’re loading external variables from a text file. It’s hard to tell from that, how advanced you are with this stuff.)

A little bit Greek

I am new I am playing around with flash for about 2 weeks (on a deadline) so I am tearing into it.

My biggest worry is reading the vars to be honest.

Can I use

loadMovieNum(f1p0, 0);

and have it read the var in the text file??

nope… though it will import any variables that are stated inside that swf that’s being loaded.

If you’re that new… I’ll give you a good post in about an hour or so that should get you on the right track.

loadVariable(); for loading variables into a target.
loadVariableNum(); for loading variables into a level.
loadMovie(); for loading swfs into target movie clips.
loadMovieNum(); for loading swfs into a level.

Take a quick look at my tutorial pages 101 at www.centerspin.com while you’re waiting for my post. You may find something useful in there. At the very least it’s helpful for understanding the terminology I use when I post Flash info.

Thanks David!

ok… this is taking a while. I’m working out the basics, then I’ll send you an FLA with lots of // comment tags. You should be able to sort it out pretty easy. This will probebly take me a hour or two though. bear with me.

Thanks again!

ok… all of my source files can be found here

http://www.centerspin.com/downloads/loader.zip

here is what I did.

I have a single blank movie clip set off stage with the following code attached to it

//this onClipEvent fires it’s code whenever something finishes
//loading into it.
onClipEvent(data){
_root.beginLoad();
}

I have the blank movie clip in my library set up with “Export” “Linkage”. set to the tag “blnkclp”. If you don’t know about linkage, and you have any questions, feel free to ask. Basicaly, it allows us to use the attachMovie() method on it, bringing in an instance of it at run time, to our movie.

the syntax for this method is

object.attachMovie(“linkageName”,“UniqueInstanceName”,depth);

in frame one of the main timeline I have this code


//lets load up those variables into the clip called varHolder
loadVariables(“movieNameLst.txt”,_root.varHolder);

//these are the location array
//first array handles y location second handles x location
//first number in the row, handles the first movie loaded in the list
//note though… it seems that the for in loop gets the last on the list first. So number f3 is at 0/0
locationy = new Array(0,100,200);
locationx = new Array(0,0,0);
//define function beginload.
function beginLoad(){
//initialize i
var i=0;
//for loop executes its script for each var in varHolder
for (var prop in varHolder){
//attach a blank movie clip to the stage for loading
_root.attachMovie(“blnkclp”,prop,i);
// trans=varHolder[prop];
// trace (trans);
//load a movie based upon the var into the target blank clip
loadMovie(varHolder[prop]+".swf",prop);
//call out to another function sending along the var “i” with
setLoc(prop,i);
//incriment i
i++;
}
}
// define the function setLocation
function setLoc(prop,i){
//set the _x property of the movie clip var loc, equal to the var loc of the array
_root[prop]._x=locationx*;
//see above
_root[prop]._y=locationy*;
}


so basicaly what it’s doing is, using a for loop to detect every variable that was loaded into the movie clip with the instance name “varHolder”. and for each variable it’s attaching a movie clip and then calling to a function which places that movie clip in the proper coordinate.

The flaw with this is that it does not, to my satisfaction, fully utilize flash. I should be able to set up an array to handle that data… I just can’t figure out how at this moment.

for now though… this is efficient and it works.

If you need help altering your files to this method, don’t be afraid to ask me to explain some aspect of it in more detail. That should be more than a mouthfull for now though.

enjoy

What can I say David?

I really appreciate it.

hey… no problem. I needed practice with my attachMovie(); AND my loadVariables();, AND my for in loops. It was good experience which I’m actually using on my own site today.