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

just_a_dude picture just_a_dude · Nov 25, 2009 · Viewed 7.7k times · Source

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

Answer

Aaron picture Aaron · Nov 25, 2009

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);