Get size of swf/jpg being loaded?

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!!!

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

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.

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…

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.

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…

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.

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 :slight_smile:

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…

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.