Zoom To A Point

snipped by lolablissie

A function to zoom to a certain point at a certain scale.

public function zoomToPoint(scale:Number, centerTarget:Point, pointToZoom:Point):void{ //pointToZoom is the point that will be moving, centerTaget is where it is moving to
 
 
 
			var centerX = centerTarget.x;
			var centerY = centerTarget.y;
			var tarX = (centerX - (pointToZoom.x*scale));
			var tarY = (centerX - (pointToZoom.y*scale));
 
			var scaleMatrix:Matrix = new Matrix();
			scaleMatrix.scale(scale, scale);
			this.transform.matrix = scaleMatrix;
			this.x = tarX;
			this.y = tarY;
 
		}

This example will zoom around the point that gets clicked:

var parentMC:MovieClip = MovieClip(parent);
var toX=parentMC.mouseX;
var toY=parentMC.mouseY;
var centerTarget:Point = new Point(toX, toY);
 
var tarX = mouseX;
var tarY = mouseY;
var pointToZoom:Point = new Point(tarX, tarY);
 
zoomToPoint(2, centerTarget, pointToZoom);