Search code examples
actionscript-3mathmatrixdisplayobject

AS3 using a Matrix to "scale" an object from its "center"


Here's something I'm trying to figure out concerning display objects in ActionScript3 / Flex. Let's say you have a display object who's registration point is in the top left and you want to scale it from its center (middle of the display object), How could you easily acheive this with the flash.geom.Matrix class

Thanks for your help


Solution

  • This is done by translating the object to the desired center of scale/rotation, scale/rotate it and then translate it back.

    You can do that with a single matrix by concatenating the matrices to get a single matrix:

    var m:Matrix = new Matrix();
    m.translate(-centerX, -centerY);
    m.scale(scaleX, scaleY);
    m.translate(centerX, centerY);