Search code examples
flashactionscript-2flash-cs4

Flash AS2 Scale an MC from center position


I am using AS2 and I'm looking for a way to scale an MC from the center meaning that the width will expand equally on both sides.

For example .. If the movie clips needs to expand +10 then it would be +5 on the left and +5 on the right.

So, in order to simulate the movie clip going forward the position on the left would offset -5 then scale.

Hope this makes sense, if not just let me know.


Solution

  • If all you care about is scaling, it's somewhat easy to do it:

    var widthDiff : Number = newWidth - mc._width;
    var heightDiff : Number = newHeight - mc._height;
    
    var bounds:Object = mc.getBounds(this);
    var moveXPerc : Number = (bounds.xMin / (bounds.xMin + bounds.xMax))-0.5;
    var moveYPerc : Number = (bounds.yMin / (bounds.yMin + bounds.yMax))-0.5;
    mc._width = newWidth;
    mc._height = newHeight;
    mc._x = mc._x + (moveXPerc * widthDiff);
    mc._y = mc._y + (moveYPerc * heightDiff);