External jpg size

I made a movie who open a number of external images, based on a text file, and I must know their size (the width and height) for a good positioning.

There is a way to find out from Flash what size a jpg has? Now I put their size in the text file, but I have a lot of parameters there and I want to get rid of this.

Hi,

You can load them in an emptyMovieClip and when you’re sure that’s loaded (bytesLoaded == bytesTotal) set its X and Y scale
to 100 (container._xscale = container._yscale = 100).
Now container._width and container._height should be those of the jpg.

SHO

It doesn’t work. I tried with an empty MC, but the container._width is 0 even after I did what you said, and also with a MC who had initial width=XXX, height=YYY; after I load the image in the container, its width and height are the same with the initial values.

Are you sure that the jpg is fully loaded?

Because I use this all the time and it works for me!

container.getBytesLoaded()>40 && container.getBytesLoaded()== container.getBytesTotal()

Here is the code I put a button:


_root.mymovie.loadMovie("image.jpg");
if(_root.mymovie.bytesLoaded == _root.mymovie.bytesTotal)
{
	_root.mymovie._xscale=100;
	_root.mymovie._yscale=100;		
// dynamic text used to display the images's width
	_root.marker=_root.mymovie._width;
}

The dynamic text display “0”. What’s wrong?

i think you can’t have the _width and _height of a jpg - you’ve got to list it yourself in an array…

search the forums, this has been discussed loads of times before =)

*Originally posted by Thorr *
if(_root.mymovie.bytesLoaded == _root.mymovie.bytesTotal)

this condition will always be true as the first time you check both equal 0 and consequently the size of the MC equals its original size as nothing has loaded onto it yet.

container.getBytesLoaded()>40 && container.getBytesLoaded()== container.getBytesTotal()

or
if(_root.mymovie.getBytesTotal > 40 && _root.mymovie.getBytesLoaded == _root.mymovie.getBytesTotal)

this other way you make sure that it only compares the bytes loaded against the total bytes if the movie has started to load so its bytesTotal is not 0(zero).

I use this all the time and it works for me!

It wouldn’t be very updatetable if you had to hard code the sizes in an array, would it?

Hope it helps

SHO

I got it … stupid me. I put the action on a button, not on mc.
In the end, I’ll put the size in the text file and I’ll spare a lot of code.
Thx.

Of course! You need to check the loading on an enterframe (or interval).

But you won’t spare any code by putting the size in the text file as you have to make sure the jpg’s loaded before you do anything to it (or at least show the user that an image it’s being loaded) anyway!

Ah! and you’re welcome, any time

SHO