I am using TransformGestureEvent and StartDrag and StopDrag events and I am having some issues.
I will do my best to explain, When I zoom in, my image zooms in and its centered while zooming. After I zoom in, I start to drag to the top of my image, when I reach the top I cant scroll now more (everything is working as expected so far) but when I goto zoom out my image y axis is no longer at the top, there is a blank white space where my image should be.
Here is my code:
mapMC.addEventListener(TransformGestureEvent.GESTURE_ZOOM, zoom);
mapMC.addEventListener(MouseEvent.MOUSE_DOWN, dragStart);
mapMC.addEventListener(MouseEvent.MOUSE_UP, dragEnd);
//Zooming Method
function zoom (event:TransformGestureEvent):void{
var locX:Number=event.localX;
var locY:Number=event.localY;
var stX:Number=event.stageX;
var stY:Number=event.stageY;
var prevScaleX:Number=mapMC.scaleX;
var prevScaleY:Number=mapMC.scaleY;
var mat:Matrix;
var externalPoint=new Point(stX,stY);
var internalPoint=new Point(locX,locY);
mapMC.scaleX *= event.scaleX;
mapMC.scaleY *= event.scaleY;
if(mapMC.scaleX > 6){
mapMC.scaleX=prevScaleX;
mapMC.scaleY=prevScaleY;
}
if(mapMC.scaleY > 6){
mapMC.scaleX=prevScaleX;
mapMC.scaleY=prevScaleY;
}
if(mapMC.scaleX < 1){
mapMC.scaleX=1;
mapMC.scaleY=1;
}
if(mapMC.scaleY < 1){
mapMC.scaleX=1;
mapMC.scaleY=1;
}
mat=mapMC.transform.matrix.clone();
MatrixTransformer.matchInternalPointWithExternal(mat,internalPoint,externalPoint);
mapMC.transform.matrix=mat;
}
//Dragging Start Method
function dragStart(e:MouseEvent):void
{
mapMC.startDrag(false, new Rectangle(0,0,-mapMC.width + stage.stageWidth, -mapMC.height + stage.stageHeight));
}
//Dragging Stop Method
function dragEnd(e:MouseEvent):void
{
mapMC.stopDrag();
}
What I am expected to happen is to zoom in on centre, be able to scroll within the Rectangle in my startDrag and zoom out on center while the top of the image stays at the top of the stage and the left of the image stays on the left of the stage.
I have tried adding these two lines of code in my zoom method, it works but I cant zoom in on center:
mapMC.y = 0;
mapMC.x = 0;
Here is a link to a sample project that will show you what I mean
https://drive.google.com/open?id=0B-p_9V3gzZZTcXpQZzI0RU9ZY0k