Hi to all,
THE PROJECT:
I’m making a portfolio site in FLASH MX 2004 that displays images from an external folder, indexed in an array.
I’ve set it up so that a user clicks on a button to get a different image from an array - the images are loaded externally - the alpha value for the current image is set to zero and then the border around the image shrinks to 80x50.
Then the new image is preloaded (using a simple bar in a movie clip to graphically display this in the 80x50 border). Then the width and height of the image are read and the border is dynamically sized to fit around the image and the alpha value of that is set to 100 to show it.
THE PROBLEM:
An if statement is used so that when the border shrinks to be exactly 80x50, the call to"photo_mc.loadPhoto(image*);" is triggered, where the selected image is preloaded and the details of its width and height are retrieved to send to another function, which sizes the border and sets alpha of image to 100.
But, as the condition is always true (i.e. border remains @ 80x50 during preload), the preloader freezes, as the call to send the image to the loadPhoto function is perpetually made. When running the finished flash movie (with photos loaded locally) on my computer, obviously there is no preloader and it all works as planned. Only when you run it online this happens…
Go to
to see what I mean. (if you look on mozilla firefox you can actually see the function getting called perpetually - the preloader keeps resetting to 1pixel, but the photos eventually load!)
**PLEASE HELP ME GET ROUND THIS! **im sure its probably quite simple…
HERE’S THE RELEVANT ACTIONSCRIPT:
INFO_________________________________________________________
instance names:
photo_mc = the empty movie clip into which the images are loaded
border = the border that fits around the image displayed in photo_mc
pBar = preloader bar movie clip
-----//This function is called whenever a button is clicked to change the photo displayed in photo_mc
MovieClip.prototype.changePhoto = function() {
photo_mc._alpha = 0;
var dw = 80;
var dh = 50;
border.desize(dw, dh);
};
-----//This function shrinks the border to 80*50 pixels, into which the preloader for the image fits nicely
MovieClip.prototype.desize = function(dw, dh) {
var dspeed = 3;
this.onEnterFrame = function() {
this._width += (dw-this._width)/dspeed;
this._height += (dh-this._height)/dspeed;
if (Math.abs(this._width-dw)<1 && Math.abs(this._height-dh)<1) {
//if 80x50, execute following code…
photo_mc.loadPhoto(image*); //send image from array to load into photo_mc
}
};
};
-----//This function runs the preloader once the “photo_mc” movie clip has loaded
MovieClip.prototype.loadPhoto = function(photo) {
this.loadMovie(photo);
pBar._width = 1; //reset preloader bar to 1 pixel before displaying the preloader
_level0.onEnterFrame = function() {
var total = Math.round(photo_mc.getBytesTotal()/1024);
var loaded = Math.round(photo_mc.getBytesLoaded()/1024);
pBar._visible = true;
//PRELOADER BAR WIDTH AS % OF LOADED
pBar._width = (loaded/total)*40;
//100% = 40 pixels
if (total != 0 && loaded>=total) {
pBar._visible = false;
var w = photo_mc._width+space;
var h = photo_mc._height+space;
border.resize(w, h);
delete this.onEnterFrame;
}
};
};
-----//After this, the border is resized to fit around the photo, and the photo_mc alpha value is set to 100 to show the image