PDA

View Full Version : Photogallery image loadbar help??


cowman345
07-17-2005, 05:12 PM
Creating a photogallery. I'm loading the full-sized photos into a movieclip on my main timeline with the following bit of code:

this.loader_mc.loadMovie(whatToLoad, "loadSpot_mc");

I have a loadbar image set up on another layer of my main timeline with the following actionscript (note: i checked to make sure all objects are properly defined, etc.):

frame 1:

bytes_loaded = Math.round(this._parent.loader_mc.getBytesLoaded() );
bytes_total = Math.round(this._parent.loader_mc.getBytesTotal()) ;
getPercent = bytes_loaded/bytes_total;
this.loadbarBar_mc._width = getPercent*100;
this.loadText = Math.round(getPercent*100)+"%";
if (bytes_loaded == bytes_total) {
this.gotoAndPlay(3);
}

frame 2:

gotoAndPlay(1);

frame 3: blank

-----

So the problem is the loadbar isn't moving... it's hanging around looking 50% loaded, and the loadText says 100% even while images are loading. I'm not too experienced at loading movies dynamically, so i'm sure i'm doing something wrong. Any help would be greatly appreciated!

-dave-

justin_kink
07-17-2005, 07:20 PM
Loading jpgs, irritatingly, doesnt work the same as loading swfs.

You need to look at its width to determine whether its loaded (if the width is 0 then the pic hasnt been imported yet)

try this.


MovieClip.prototype.loadPic = function(pic) {
yourPhotoContainerMc.loadMovie(pic);
_root.onEnterFrame = function() {
var t = yourPhotoContainerMc.getBytesTotal(), l = yourPhotoContainerMc.getBytesLoaded();
percentThatsLoaded = Math.round((l/t)*100);
yourLoadingBar._visible = 1;
if (l == t && yourPhotoContainerMc._width>0 && yourPhotoContainerMc._height>0) {
var w = yourPhotoContainerMc._width, h = yourPhotoContainerMc._height;
yourLoadingBar._visible = 0;
delete this.onEnterFrame;
} else {
yourLoadingBar._width = percentThatsLoaded;
loadingProgressTextField.txt.text = percentThatsLoaded+" % loaded";
}
};
};
yourPhotoContainerMc.loadPic("yourPic.jpg");


It will resize the bar from 1 pixel to 100, depending on the percent loaded. You can use some simple maths if you want it to finish bigger or smaller than 100px, but make sure its a multiple or division of "percentThatsLoaded" as thats what gives it a changing size.

cowman345
07-17-2005, 10:26 PM
Thanks so much, greatly appreciated!

-dave-