# Getting a loaded image \_width and \_height?

**URL:** <https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797>\
**Category:** Uncategorized\
**Created:** [March 28, 2003, 1:48pm UTC](https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797 "2003-03-28T13:48:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![adham\_a](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@adham\_a](https://forum.kirupa.com/u/adham_a)\
**Post date:** [March 28, 2003, 1:48pm UTC](https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797/1 "2003-03-28T13:48:13Z")

</div>

Hello all,

I am creating a photo gallery but i have to resize my loaded images into a certain size after loading them into an empty movie clip on stage.

I am resizing my images now through multiplying the \_xscale and \_yscale of the empty movie clip after loading the image by a certain coefficient, but this implies that i have to know the loaded image size before knowing the right coefficient to use.

Is their anyway to get the \_width and \_height of the loaded image or the empty movie clip after loading the image into it, since i am getting a 0 for \_height and \_width for empty movie clip before and after loading the image.

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2003, 1:51pm UTC](https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797/2 "2003-03-28T13:51:25Z")

</div>

show us your code 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2003, 1:59pm UTC](https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797/3 "2003-03-28T13:59:03Z")

</div>

// this is the code used for the image gallery tutorial on kirupa  
// see the photo.\_xscale and photo.\_yscale code lines

this.pathToPics = “…/All Mine/Photos/”;  
this.pArray = new Array(32);  
for (kkk = 0; kkk \<= 31; kkk++) {  
if (kkk \< 10) {  
this.pArray[kkk] = “DSCF000” + kkk + “.JPG”;  
} else {  
this.pArray[kkk] = “DSCF00” + kkk + “.JPG”;  
}  
}  
this.fadeSpeed = 20;  
this.pIndex = 0;  
photo.\_xscale = photo.\_xscale_0.234375;  
photo.\_yscale = photo.\_yscale_0.208333;  
photo.\_x = 0;  
photo.\_y = 0;  
MovieClip.prototype.changePhoto = function(d) {  
this.pIndex = (this.pIndex+d)%this.pArray.length;  
if (this.pIndex\<0) {  
this.pIndex += this.pArray.length;  
}  
this.onEnterFrame = fadeOut;  
};  
MovieClip.prototype.fadeOut = function() {  
if (this.photo.\_alpha\>this.fadeSpeed) {  
this.photo.\_alpha -= this.fadeSpeed;  
} else {  
this.loadPhoto();  
}  
};  
MovieClip.prototype.loadPhoto = function() {  
// specify the movieclip to load images into  
var p = \_root.photo;  
//------------------------------------------  
p.\_alpha = 0;  
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);  
this.onEnterFrame = loadMeter;  
};  
MovieClip.prototype.loadMeter = function() {  
var i, l, t;  
l = this.photo.getBytesLoaded();  
t = this.photo.getBytesTotal();  
if (t\>0 && t == l) {  
this.onEnterFrame = fadeIn;  
} else {  
trace(l/t);  
}  
};  
MovieClip.prototype.fadeIn = function() {  
if (this.photo.\_alpha\<100-this.fadeSpeed) {  
this.photo.\_alpha += this.fadeSpeed;  
} else {  
this.photo.\_alpha = 100;  
this.onEnterFrame = null;  
}  
};  
// Actions -----------------------------------------  
// these aren’t necessary, just an example implementation  
this.onKeyDown = function() {  
if (Key.getCode() == Key.LEFT) {  
this.changePhoto(-1);  
} else if (Key.getCode() == Key.RIGHT) {  
this.changePhoto(1);  
}  
};  
Key.addListener(this);

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2003, 2:08pm UTC](https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797/4 "2003-03-28T14:08:28Z")

</div>

try this:

```auto
MovieClip.prototype.loadMeter = function() {
	var i, l, t;
	l = this.photo.getBytesLoaded();
	t = this.photo.getBytesTotal();
	if (t>0 && t == l) {
		**trace(this.photo._width);
		trace(this.photo._height);**
		this.onEnterFrame = fadeIn;
	} else {
		trace(l/t);
	}
}

```

😉 =)

[size=1] **ps.** please use actionscript formatting tags [as] and [/as][/size]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2003, 2:30pm UTC](https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797/5 "2003-03-28T14:30:33Z")

</div>

Thanks for your help

But the returned value is still 0 before and after loading the image into the movie clip for the \_height and \_width

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2003, 2:33pm UTC](https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797/6 "2003-03-28T14:33:04Z")

</div>

**!?** :stunned:

ok… i’ll download the files from the tutorial 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2003, 2:43pm UTC](https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797/7 "2003-03-28T14:43:14Z")

</div>

ok. i tested it… and it worked =)

could you attach your files? 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2003, 3:51pm UTC](https://forum.kirupa.com/t/getting-a-loaded-image--width-and--height/16797/8 "2003-03-28T15:51:17Z")

</div>

> \*Originally posted by adham\_a \*  
> \*\*Thanks for your help

But the returned value is still 0 before and after loading the image into the movie clip for the \_height and \_width \*\*  
Before, yes, after, no. Kax’s code works perfectly 🙂
