I'm loading a jpg into a movie clip, and based on its size I want to scale it so it is no larger than 350px in either width or height. I want to keep the aspect ratio the same, however.
To do this, I'm doing the following calculation:
Code:
var scale=( Math.min ( ( 350 / logo_mc._width ) , ( 350 / logo_mc._height ) ) * 100 );
logo_mc._xscale=scale;
logo_mc._yscale=scale;
The image, at this point, has an alpha value of 0%. In the next frame it begins a 10-frame tween where the alpha ends up as 100%.
I'm always ending up with a scale of 100, though. The image I'm loading in is 650px * 462px. However, the logo_mc._width and logo_mc._height are only equal to these about four frames into the alpha tween.
I've tried putting in a event handler for the logo_mc.onLoad event. This didn't work at all (i.e. the function is never event executed. Since looking at the documentation, it says that the onLoad event only occurs for clips being loaded in from the library, rather than external clips/jpegs).
I've tried putting in an event handler using the onClipEvent(load). The values of _width and _height when tested for in the function are 350px square, rather than 650 * 462 as they should be.
In desparation, I've tried looping in the code until the _width and _height are the correct values. It just enters a permenent loop and I have to crash out of flash.
This surely shouldn't be impossible - I would have thought determining the size of an image and scaling it accordingly isn't an unheard-of task, but I just can't seem to accomplish it. Please help!
Thanks in advance,
Jaucourt.