|
-
[RESOLVED] [F8] preloader code problem, please help!!!
hello.
I have two buttons on the stage and when pressed it creates a border to resize and contain and image to its dimensions. This works all well and good.
I want to add a preloader to show the progress of the image loading before it resizes. I have tried working some code to achieve a preloader but with no luck.
can anyone help or suggest what i need to do to correct the code?? any help will be much appreciated!!
space = 10;
photo_mc._alpha = 0;
MovieClip.prototype.loadPhoto = function(photo){
photo_mc._alpha = 0;
this.loadMovie(photo);
_level0.onEnterFrame = function(){
// modified the total and loaded so as to round it up
// to smaller number.
var total = Math.round(photo_mc.getBytesTotal()/100);
var loaded = Math.round(photo_mc.getBytesLoaded()/100);
var percentage:Number = Math.round(total/loaded *100);
percentDisplay.text = percentage + "%";
if (total != 0 && loaded>=total){
var w = photo_mc._width + space;
var h = photo_mc._height + space;
border.resize(w, h);
delete this.onEnterFrame;
}
}
};
MovieClip.prototype.resize = function(w, h){
//the higher the slower the resize of the border
var speed = 4;
this.onEnterFrame = function(){
this._width += (w - this._width)/speed;
this._height += (h - this._height)/speed;
if( Math.abs(this._width-w)<1 && Math.abs(this._height-h)<1){
this._width = w;
this._height = h;
photo_mc._x = this._x - this._width/2 + space/2;
photo_mc._y = this._y - this._height/2 + space/2;
photo_mc._alpha = 100;
delete this.onEnterFrame;
}
}
};
btn1.onRelease = function() {
photo_mc.loadPhoto("p.jpg");
};
btn2.onRelease = function() {
photo_mc.loadPhoto("p2.jpg");
};
-
code looks ok. what doesn't work?
gparis
-
haha, I must have been very tired when posting this. thankyou for your time anyway!!!
I have had some trouble with it earlier but yes it does work fine!!!
how silly!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|