-
- package example {
-
- import flash.display.Sprite;
- import flash.geom.Point;
- import flash.geom.Matrix;
-
-
-
- public class VirtualCentreSprite extends Sprite {
-
-
-
- protected function scaleAround( offsetX:Number, offsetY:Number, absScaleX:Number, absScaleY:Number ):void {
-
- var relScaleX:Number = absScaleX / this.scaleX;
- var relScaleY:Number = absScaleY / this.scaleY;
-
- var AC:Point = new Point( offsetX, offsetY );
- AC = this.localToGlobal( AC );
- AC = this.parent.globalToLocal( AC );
-
- var AB:Point = new Point( this.x, this.y );
-
- var CB:Point = AB.subtract( AC );
- CB.x *= relScaleX;
- CB.y *= relScaleY;
-
- AB = AC.add( CB );
-
- this.scaleX *= relScaleX;
- this.scaleY *= relScaleY;
- this.x = AB.x;
- this.y = AB.y;
- }
-
-
-
-
- protected function rotateAround( offsetX:Number, offsetY:Number, toDegrees:Number ):void {
- var relDegrees:Number = toDegrees - ( this.rotation % 360 );
- var relRadians:Number = Math.PI * relDegrees / 180;
- var M:Matrix = new Matrix( 1, 0, 0, 1, 0, 0 );
- M.rotate( relRadians );
-
- var AC:Point = new Point( offsetX, offsetY );
- AC = this.localToGlobal( AC );
- AC = this.parent.globalToLocal( AC );
-
- var AB:Point = new Point( this.x, this.y );
-
- var CB:Point = AB.subtract( AC );
-
-
- CB = M.transformPoint( CB );
- AB = AC.add( CB );
-
- this.rotation = toDegrees;
- this.x = AB.x;
- this.y = AB.y;
- }
-
- }
-
- }