# Get size of swf/jpg being loaded?

**URL:** <https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476>\
**Category:** Uncategorized\
**Created:** [May 21, 2003, 11:30pm UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476 "2003-05-21T23:30:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbrewer](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@jbrewer](https://forum.kirupa.com/u/jbrewer)\
**Post date:** [May 21, 2003, 11:30pm UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476/1 "2003-05-21T23:30:42Z")

</div>

i feel real dumb today… i want the swf or jpg that i load into an empty clip in my main movie to scale to the size of the stage.  
How do i get the height and width of the jpg/swf being loaded?  
i was thinking i could take that info and do a little ratio action and scale it to fit…  
please help!!!

---

<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:** [May 22, 2003, 12:53am UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476/2 "2003-05-22T00:53:56Z")

</div>

as far as i know, i don’t think there’s a way to retrieve any information about a dynamically loaded pic.

---

<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:** [May 22, 2003, 3:55am UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476/3 "2003-05-22T03:55:28Z")

</div>

After it loads you can change the properties of the empty clip you loaded to. Changing those properties will in turn effect the object loaded into that clip. You can only do this AFTER the object has loaded into Flash I believe.

---

<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:** [May 22, 2003, 4:48pm UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476/4 "2003-05-22T16:48:59Z")

</div>

i think you are right, but i am having a hard time figuring out how to get the newly loaded to scale up to the stage size?  
empty\_mc.\_width = 550;  
empty\_mc.\_height = 400;  
how do i figure out the necessary scaling if the loading pics are different sizes?  
i should know this, but i am blank…

---

<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:** [May 22, 2003, 4:55pm UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476/5 "2003-05-22T16:55:45Z")

</div>

I am blank as well. I am assuming using an if statement to see if the width and height are within parameters and if not then resize. But it will be a pain because for this you will need to use \_xscale and \_yscale, which resizes on a percentage unlike \_width and \_height resize on exact pixels.

So setting \_xscale and \_yscale to 50 would reduce the width and height by 50%, making it keep the same dimensions, but shrinking it down.

But setting \_width and \_height to 50 would reduce the width and the height to a 50x50 square.

But since you need to go by percentage you will need to figure out some kind of equation on how to resize it depending on how much bigger the image is to the stage. For that I am stumped.

---

<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:** [May 23, 2003, 11:41am UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476/6 "2003-05-23T11:41:12Z")

</div>

the math is easy,  
but the pb is that if your pictures have a different width to height ratio than the stage, it can’t work…

---

<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:** [May 23, 2003, 12:39pm UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476/7 "2003-05-23T12:39:31Z")

</div>

Why work with the scale? Just use \_width and \_height. But as Eyez said, your pics will be distorted if they don’t have the exact same size, with a round width to height ratio with the Stage.

```auto
this.createEmptyMovieClip("container",0);
container.loadMovie("bla.swf");
this.onEnterFrame = function(){
  var l = container.getBytesLoaded();
  var t = container.getBytesTotal();
  if (l && l >= t){
    // Use _width and _height
    container._width = Stage.width;
    container._height = Stage.height;

    // Use _xscale and _yscale
    var ratio = Stage.height / container._height;
    // The problem could come from the fact that this ratio
    // might be different from Stage.width / container._width
    container._xscale = container._yscale *= ratio;
  }
}

```

pom 🙂

---

<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:** [May 23, 2003, 4:05pm UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476/8 "2003-05-23T16:05:27Z")

</div>

that is awesome, i was working with the container.\_h & \_w = Stage.\_h & \_w, and wasn’t getting any results… thats because i forgot to put an onEnterFrame in the mix!!! I modified the code a bit cos i was getting an empty space on the right edge(width)…

this.createEmptyMovieClip(“container”, 1);  
container.loadMovie(“03.jpg”);  
this.onEnterFrame = function() {  
var l = container.getBytesLoaded();  
var t = container.getBytesTotal();  
if (l && l\>=t) {  
// Use \_width and \_height container. \_width =Stage .width ;  
container.\_height = Stage.height;  
container.\_width = Stage.width;  
// Use \_xscale and \_yscale  
var Xratio = Stage.height/container.\_height;  
var Yratio = Stage.width/container.\_width;  
// The problem could come from the fact that this ratio  
// might be different from Stage.width / container.\_width  
container.\_xscale \*= Xratio;  
container.\_yscale \*= Yratio;  
}  
};

so thank you again - this will help with another project i have in mind…

---

<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:** [May 23, 2003, 4:07pm UTC](https://forum.kirupa.com/t/get-size-of-swf-jpg-being-loaded/21476/9 "2003-05-23T16:07:21Z")

</div>

Ilyas: Your method for \_width and \_height makes the image fill the whole stage. I was under the impression that what jbrewer wanted to do what check if the image itself was too big and if so scale it down so that it won’t be.

I didn’t test your code so your \_xscale and \_yscale method may do this.
