Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Preload dynamically loaded jpgs?

Posted on 2003-03-23
Medium Priority
Last Modified: 2010-04-03
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

     //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");



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
Question by:kris_mcl
  • 8
  • 7

Expert Comment

ID: 8191448
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 ... ???
LVL 23

Expert Comment

ID: 8191759
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.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 8192803
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!


Expert Comment

ID: 8194674
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.

Author Comment

ID: 8196232
Thanks Henry, that would be great if you had a minute to make a simpler fla file.

I really appreciate your help!


Expert Comment

ID: 8198498
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 ...


Author Comment

ID: 8204236
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!


Expert Comment

ID: 8204370
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?

Author Comment

ID: 8204428
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... :)

Author Comment

ID: 8204445
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!

Expert Comment

ID: 8204500
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 ...


Author Comment

ID: 8204535
awesome, thanks Henry!

Accepted Solution

henryww earned 400 total points
ID: 8212588

Author Comment

ID: 8213520
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.


Expert Comment

ID: 8213567
u are welcome :)

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question