It’s a fairly straightforward operation – I’m placing ‘handles’ at regular points of a DisplayObjectContainer. These handles will be used to scale, rotate a la Illustrator, etc.
I know this can be done with some fairly simple maths but I spent all my maths lessons drawing stick-men dying in increasingly creative ways.
TargetW/targetH are the original width/height of the object I’m adding the handles to. Obviously, adding the handles increases width/height so they are stored beforehand.
protected function positionHandles():void {
handles[0].x = 0;
handles[0].y = 0;
handles[1].x = targetW / 2;
handles[1].y = 0;
handles[2].x = targetW;
handles[2].y = 0;
handles[3].x = 0;
handles[3].y = targetH / 2;
handles[4].x = targetW / 2;
handles[4].y = targetH / 2;
handles[5].x = targetW;
handles[5].y = targetH / 2;
handles[6].x = 0;
handles[6].y = targetH;
handles[7].x = targetW / 2;
handles[7].y = targetH;
handles[8].x = targetW;
handles[8].y = targetH;
}
1 Answer