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

1

8

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

Zebulen answered 25/11, 2009 at 16:20 Comment(0)
C
8

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);
Centroclinal answered 25/11, 2009 at 16:25 Comment(2)
translate() and scale() aren't static methods. You need to call them from a Matrix instance.Bachelor
And by the way, the return value on both of those methods is void.Bachelor

© 2022 - 2024 — McMap. All rights reserved.