# Gallery image loading - getting image width..help!

**URL:** <https://forum.kirupa.com/t/gallery-image-loading-getting-image-width-help/183979>\
**Category:** Uncategorized\
**Created:** [March 31, 2006, 5:44pm UTC](https://forum.kirupa.com/t/gallery-image-loading-getting-image-width-help/183979 "2006-03-31T17:44:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![darkhorse581](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@darkhorse581](https://forum.kirupa.com/u/darkhorse581)\
**Post date:** [March 31, 2006, 5:44pm UTC](https://forum.kirupa.com/t/gallery-image-loading-getting-image-width-help/183979/1 "2006-03-31T17:44:50Z")

</div>

Ladies and gents:

having a problem with my code somewhere; I’m stumped. Here’s what i’m trying to do:

-When you click on a thumbnail in my gallery a load bar appears that is the width of the loading image  
-While the image loads the load bar scales from full width to zero  
-Once it finishes loading the image fades in  
-Click on a new thumbnail, and the old image fades out, then the scrollbar is supposed to take the width of the NEW image and do the same thing

What is happening is that the scrollbar width does not set itself to the new image size until i click the thumbnail a second time…try this link to see what i mean. it’s on the “portfolio” page.

[http://www.lewisweb.ws/staging](http://www.lewisweb.ws/staging)

here’s the code:

```auto
//CONSTANTS
frame_x = 387; //the exact x coordinate where the box originates
frame_y = 184; //the exact y coordinate where the box originates
alphaSpeed = 5; //spped at which the pics fade in

//INITIAL SETTINGS
containerMC._alpha = 0;
containerMC._x = frame_x;
containerMC._y = frame_y;

//Fades in a picture loaded externally
MovieClip.prototype.loadPic = function(pic){
    containerMC.fadeOldPic(); //fade out old picture
    containerMC._alpha = 0;
    this.loadMovie(pic); //load new pic
    var loadIsComplete = false; //reset load checker
    var w = containerMC._width;     
    loadBar._width = w; //set loadbar to new movieclip width
    loadBar._alpha = 100; //make loadbar opaque
    _root.onEnterFrame = function(){
        var t = containerMC.getBytesTotal(), l = containerMC.getBytesLoaded();
        loadIsComplete = (Math.round(l/t) == 1); //check to see if load completed
        loadBar._width = w - ((l/t) * w); //sets width of loadbar dynamically
         if (loadIsComplete){
            containerMC._alpha += alphaSpeed; //if load is complete, fade pic in
        }
        //if the load is complete and the picture is fully faded in...
        if (t != 0 && loadIsComplete && _root.containerMC._alpha == 100){            
            loadBar._alpha = 0; //make the load bar disappear
            delete _root.onEnterFrame;
        }
    }
};

//Fades out an old picture...pretty self explanatory
MovieClip.prototype.fadeOldPic = function(){
    _root.onEnterFrame = function(){
        _root.containerMC._alpha -= alphaSpeed;
        if (_root.containerMC._alpha == 0){            
            delete _root.onEnterFrame;
        }
    }
};

containerMC.loadPic("portfolio/westin.jpg");
stop();

```

ANY help will be appreciated!

---

<div class="post-metadata">

**Author:** ![rhamej](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@rhamej](https://forum.kirupa.com/u/rhamej)\
**Post date:** [April 1, 2006, 2:38am UTC](https://forum.kirupa.com/t/gallery-image-loading-getting-image-width-help/183979/2 "2006-04-01T02:38:11Z")

</div>

Question, how do you know the width of something that flash hasnt loaded yet 😉 Cant be done. Thats why it works the second time, because its already cached in the temp files. If you are using XML or PHP, you could always pass the width over to flash so it knows what the width is before its loaded. =)

---

<div class="post-metadata">

**Author:** ![darkhorse581](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@darkhorse581](https://forum.kirupa.com/u/darkhorse581)\
**Post date:** [April 3, 2006, 5:23pm UTC](https://forum.kirupa.com/t/gallery-image-loading-getting-image-width-help/183979/3 "2006-04-03T17:23:29Z")

</div>

That would make sense of course. I figured as soon as the loadmovie command processed that the height and width in the image header was stored…guess not!

i’m working on making this XML based anyway so that’ll eliminate that problem.

thanks!

> [@rhamej](#):
>
> Question, how do you know the width of something that flash hasnt loaded yet 😉 Cant be done. Thats why it works the second time, because its already cached in the temp files. If you are using XML or PHP, you could always pass the width over to flash so it knows what the width is before its loaded. =)
