Link to home
Start Free TrialLog in
Avatar of kris_mcl
kris_mcl

asked on

Preload dynamically loaded jpgs?

Hi all,
I am working on a project that dynamically loads jpg images whose names are called from an external text file. I have it working well using the loadMovie() function, the only thing is that I would like to preload these images all at once and display a simple progress bar, then proceed to the first frame of my main scene.

I have no trouble with standard preloading practices, but this is the first time I've needed to preload dynamic elements. I found a page with some info on the subject at http://news.flashguru.co.uk/?aid=000044 , but I am a little(!) confused by it.

Here is the relevant portion of the code I have written so far:

****begin code

var whichtut
loadVarsText = new loadVars();
loadVarsText.load(whichtut + ".txt");
loadVarsText.onLoad = function(success) {
     if (success) {
          titlebox.html = true;
          titlebox.htmlText = this.title;
          instructions.html = true;
          instructions.htmlText = this.start;
          statusbox.html = true;
          statusbox.htmlText = "Step <b>"+[_currentframe-1]+"</b> of <b>"+this.numsteps+"</b>";
     } else {
          trace("error - text data not loaded");
     }

     //convert number of steps from text file to an integer
     numsteps=parseInt(this.numsteps);

     //if current step == total number of steps, disable "next" button
     if (numsteps == _currentframe-1) {
          nextbutton.enabled = false;
     } else{
          nextbutton.enabled = true;
     }    
_root.createEmptyMovieClip("graphic", 10);
graphic._x = 67;
graphic._y = 50;
thisgraphic = this.pic00;
loadMovie(thisgraphic, "graphic");

stop();

};
stop();

end code*****

As you can see, what I want to do is to preload the images that are loaded into the movieclip "graphic".

Please post any insight you might have into this issue.
Thanks in advance,
Kris M
Avatar of henryww
henryww

so u want to preload all the images before user can use the next button??

or one by one and user can get to see as much as loaded ... ???
you're making something simple into something quite complicated..
the images may as well be embedded in the movie..
however seeing you've taken the route you have if you
import the images to the library and then drag and drop them around and well outside the stage in the first few
frames where your preloader is..the player is forced to
load them along with the other content.
if they are spread over several frames you can track the
advancing player in a preloader..frame by frame..to give
you the progress graph.

Z
Avatar of kris_mcl

ASKER

Thanks for the comments, guys/gals.

This may not have been clear in my first post, but the reason that the images cannot be embedded is that this is an instructional tutorial that I am building. It will be an empty shell that will have its content supplied by an external text file, so that the client does not need to have Flash to create their own tutorials.

Basically, it functions as a simple slideshow: each frame loads a short paragraph of text into a dynamic text field, as well as a corresponding image whose filename is specified in the text file.

I would like all of the jpg files that are specified in the text file to be preloaded before the user begins the tutorial. I've tried to do this by using createEmptyMovieClip(), but I cannot figure out how to get this dynamic content to preload.

Henryww, I've had a look at the sq.fla file, as well as that other thread you linked. It seems to do what I want it to, but I'm having trouble adapting its concepts to my own needs. Statements such as
"var jpgFiles = /:snMatrix["s"+ /:thisSection+ "_" + (l2Counter)].split(",");" are giving me trouble. I presume that this is a reference to a matrix in a database prog., but I'm not sure how it can be bypassed since I'm not using a DB, just a txt file.

Thanks again for all the help, I'm pretty close to figuring this puppy out. Any additional insight you could provide would be stellar!

Cheers,
KM
as Z stated there are many ways to do it and the simplest way to do a static swf and load it in like Z suggested.

"var jpgFiles = /:snMatrix["s"+ /:thisSection+ "_" + (l2Counter)].split(",");" are giving me trouble. I presume that this is a reference to a matrix in a database prog., but I'm not sure how it can be bypassed since I'm not using a DB, just a txt file."

the example is also loading from the data.txt
u add files (jpg) to a folder, change the txt file for the sections and the images + descriptions ... etc ...

it is a bit complex there, it loads more than one sub-sections (level 2 + different number of images) and generate the menu dynamically. i had removed quite a lot of the code so it only have 1 section (photos)... an easier way to organise the data will be using XML. which is what i am doing for the final site.

let me make a simpler fla for u ... just to preload all the jpgs and show a "start" button when it is all loaded.
Thanks Henry, that would be great if you had a minute to make a simpler fla file.

I really appreciate your help!

cheers,
km
kris_mcl, i have uploaded a file call sq_trim.zip at the same location ...

which i have changed the text file (data1.txt) and the confusing code in the sqloader movieclip.

u should able to follow it a bit easier ... hopefully ..
let me know if u have problem understanding it ...

cheers
thanks for the new file, henry. It does make more sense, though the dynamic menu portions are still kind of throwing me off.

it seems like there are only a few scripts that are actually involved with the preloading, but I'm having trouble picking out exactly which ones they are among the other things like fadein, fadeout, dynamic menu, etc.

could you point me to just those scripts that are responsible for the preloading?

thanks again for all your help!

so u don't need the fading? ...

like u just need a very simple way to preload the jpgs (+ create movieclip to as the holder) and ... then?

buttons to netvigate"previous" + "next" when everything is loaded?
yep, that's all I need. Would it be possible to get that file chopped down a little more?

BTW, sorry for being so thick... :)
I should add, all I really want is a way to preload the external jpgs. Once I have that part figured out, I'll be able to use the concept in various movies, with or without effects such as a fadein/fadeout.

thanks man!
that's ok man .. i know the sample fla is a bit hard to understand, it was intended to do more complex stuffs ...

anyway that shouldn't be too hard, i have to finish off what i am doing now and i will get this done a bit later ...


cheers
awesome, thanks Henry!
ASKER CERTIFIED SOLUTION
Avatar of henryww
henryww

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Henry! That looks like just what I needed. I'll have a closer look at it when I get a few minutes, but it looks very clear on first glance.

This is a concept I'll be able to get a lot of mileage out of, so I'll be sure to hang on to your file as reference.

I really appreciate all the time you took helping me out. Thanks very much.

//km
u are welcome :)