[thelist] Flash: Scaling a loaded image to Xpx and Ypx?

Benjer futureweb at macmail.com
Tue Oct 15 04:11:00 CDT 2002


This probably looks a bit daunting if you've never used enterFrames...

function displayImg(img, imgMC, imgHeight, imgWidth) {
    imgMC.loadMovie(img);
    //check the download status of the external
    //movie once every frame
    this.onEnterFrame = function() {
        //trace the percentage of the movie that has loaded
        percent =
(this.holder.getBytesLoaded()/this.holder.getBytesTotal())*100;
        if (!isNan(percent)) {
            trace(percent+"% loaded");
        } else {
            trace("0% loaded");
        }
        //once fully loaded we can re-size the image
        if (percent == 100) {
            img._width = imgWidth;
            img._height = imgHeight;
            delete this.onEnterFrame;
        }
    }
}
displayImg("http://localhost/Test/249-2.jpg", "myImage", 125, 200);

Modified version of flashguru's code

http://www.flashguru.co.uk

Ben

On 15/10/02 4:22 am, "Frank" <framar at interlog.com> wrote:

>
> I'm still in the painful newbie stage of learning Flash MX
> Action Script. I've learned how to dynamically load a jpg
> into a movie. The images that will be uploaded will very
> rarely be of the exact same dimensions, so scaling percent
> wise doesn't exactly do what I want. I would like to scale
> an image up and down to a precise amount of pixels (say,
> 150px high by 250px wide)
>
> Here is my current code, can someone offer an alternative?
>
> ---
> function displayImg(img, imgMC, imgHeight, imgWidth) {
>       img = loadMovie(img, imgMC);
>       img._yscale = imgHeight;
>       img._xscale = imgWidth;
> }
> img = "http://localhost/Test/249-2.jpg";
> imgMC = "myImage";
> displayImg(img, imgMC, 125, 200);
> ---
>
> Thanks.
>
> --
> Frank Marion
> Tel. 416 825 7488
> framar at interlog.com
> http://www.frankmarion.com

<!------------------------
futureweb at macmail.com
------------------------->





More information about the thelist mailing list