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.
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.
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.
_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;
}
*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.
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?
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!