AS3 Quick Tips: Scale a movieclip proportionately

Flash CS3 Professional

Hello there, Have you ever wondered how to scale a movieclip in proportion to height or width? Well this quick tip is here to help you do just that!

Lets get right to the juicy stuff:

myMovieClip_MC.width = 300;
myMovieClip_MC.scaleY = myMovieClip_MC.scaleX;

This code will scale the target clip (myMovieClip_MC) to 300 width or any other desired width!

To do this for height simply reverse the methods to the opposite:

myMovieClip_MC.height = 300;
myMovieClip_MC.scaleX = myMovieClip_MC.scaleY;

Isn’t it amazing! Now go with your new found knowledge and conquer your AS3!

Tags: , , , , , , , , , ,

  • http://www.stringcheeseradio.com jeremy

    this doesn’t do what I thought it would

  • http://www.bigtallbill.co.uk Bill Nunney

    What were you expecting it to do?

  • Neoviper

    This did exactly what I thought it would, have been looking for how to do this for a little while now. Way easier than the way I was trying to do it, was trying to mathematically get a number to scale by based on the target size and the current size. Didn’t work at all.

  • aleksandar

    how to make my mc scale every time i enter that frame on which mc is ?!?!? 10x as3… ;)

  • Bill Nunney

    Hi Aleksandar,

    addEventListener(Event.ENTER_FRAME, eventHandler);

    function eventHandler(event:Event):void
    {
    MovieClip_MC.height += 1;
    MovieClip_MC.scaleX = MovieClip_MC.scaleY;
    }

    would be a very simple way to achieve it :)

  • Nico Limpika

    For the users coming to this page looking for information on scaling a movie clip proportionally around certain point regardless of its scale or location I found this article to be very useful. You bloggers rock on!

    http://www.actionscript-flash-guru.com/blog/33-scale-around-a-point-transform-multiple-objects-actionscript-3-as3

  • http://scorpafied.deviantart.com xdeath

    ok well typically in a gallery it does scale both. it normally keeps it in proportion when scaling. so this is what it should have been:

    if(p.width>p.height){
    p.width = 100;
    p.scaleY = p.scaleX;
    }
    else if(p.height>p.width){
    p.height = 80;
    p.scaleX = p.scaleY;
    }

    “p” is what i called my movieclip. in the above example he called his “myMovieClip_MC”. feel free to use this. in return though if you have a spare moment check out my deviantart page at scorpafied.deviantart.com

  • http://mindstrom.blogspot.com Vinod

    Hi,
    After scaling to desire height and width how to reset back to original. Im sacleing the movieclip which holds swf. On load of another swf the zoom sticks to the same.
    var scaleValue:Number = 10;
    function zoom_in(e:Event):void
    {
    emc.width += scaleValue;
    emc.height += scaleValue;
    }
    function zoom_out(e:Event):void
    {
    emc.width -= scaleValue;
    emc.height -= scaleValue;
    }
    zoomin.addEventListener(MouseEvent.CLICK, zoom_in);
    zoomout.addEventListener(MouseEvent.CLICK, zoom_out);

  • Asdf

    Why yes Master… I will use this knowledge to conquer my AS3… God Speed Obi One.