PDA

View Full Version : help preloading external photos


smerbie
02-25-2006, 05:54 AM
I am creating a dynamic photo gallery. The gallery will be broken into 3 categories for each set of photos. I want each category to be in its own movie clip. When I click on each photo thumbnail, I want its full size photo to preload before it appears. I am using the progressBar component and the scrollPane component to accomplish this (I built this from a tutorial). The preloader works great when everything is on Scene 1 (I built this on the main scene to test it.) but when I move everything inside of a movie clip which I'll call "webGallery" the photos still load but the preloader does not work anymore. Thanks in advance! (Flash MX 2004 Pro - publishing SWF as Player 6, A.S. 2.0)

I have included the actionscript below:

// Create a listener object event function. The progress bar is an object so needs an object function to work
myProgressBarListener = new Object();

// When the progress bar is complete and has preloaded the Scroll Pane component content, the listener will call and run this code below:
myProgressBarListener = function (eventObject) {

// Hide the progress bar now as we don’t need it any more
myProgressBar._visible = false;

// Closes the above function
};

// Set the location of the content to be loaded
large.contentPath = loadMovie(place+".jpg", "large");

// Declares a listener that detects when the progress bar component has loaded the loader component content and is complete. Then calls the function myProgressBarListener
myProgressBar.addEventListener("complete", myProgressBarListener);

// Set up the progress bar component variable to polled mode.
myProgressBar.mode = "polled";

// The location of the Scroll Pane Component
myProgressBar.source = "large";

// Sets the conversion to 1. This basically means the component divides the current and total values loaded and to be loaded. Then it floors them (works out the difference between them) and displays the converted value in the label property
myProgressBar.conversion = "1";

// Set the label to display the word 'loading' followed by the percentage value loaded so far
myProgressBar.label = "LOADING %3%%";

// The direction the progress bar moves when loading
myProgressBar.direction = "right";

// The location of the label that displays the percentage loaded so far
myProgressBar.labelPlacement = "bottom";

// Stop the movie at the frame until the move has been preloaded
stop();

astgtciv
02-25-2006, 07:03 AM
but when I move everything inside of a movie clip which I'll call "webGallery" the photos still load but the preloader does not work anymore.

Probably, myProgressBar is defined in the scope of _root, so that when you move your code, it can not reference it anymore. To fix it, you could add the following line at the beginning of your code:


var myProgressBar = _root.myProgressBar;
...


And please add ... around your as code for better readability.

smerbie
02-25-2006, 07:34 AM
Probably, myProgressBar is defined in the scope of _root, so that when you move your code, it can not reference it anymore. To fix it, you could add the following line at the beginning of your code:

I added the variable to my code but it did not work. Do you think I need to add _root any where else in the code??

astgtciv
02-25-2006, 07:42 AM
I was surprised that your photos still load, in fact, because doing


// Set the location of the content to be loaded
large.contentPath = loadMovie(place+".jpg", "large");


should also not work once the code is moved to inside of a movieclip. You need to make every reference to another movieclip (or variable like place - unless it's defined in the same location) either prefaced by "_root." (as in _root.large) or do the same var trick (var large = _root.large; ) once in the beginning...

Did you post all the code? If it still doesn't work, post your fla.

smerbie
02-25-2006, 05:39 PM
That is all of the code for the preloader. I can't post my source cose. It exceeds the file size limit for this forum.

smerbie
02-25-2006, 05:51 PM
I made a change to the following code and now it works...

Original:
// The location of the Scroll Pane Component
myProgressBar.source = "large";

Changed to:
// The location of the Scroll Pane Component
myProgressBar.source = "_root.webGallery.large";

I didn't have to change anything else. Pretty crazy stuff!

Thanks for your help though!