SimanisJKT48
SimanisJKT48

Reputation: 104

Zoom Objek on center stage as3

 buttonZoomIn.addEventListener(MouseEvent.MOUSE_DOWN, zi_begin);
    function zi_begin(e:MouseEvent):void
    {
    if(map.scaleX < 6)
        {
        map.scaleX += 0.5;
        map.scaleY += 0.5;
        }

I have images that can be enlarged ... but the image is enlarged from the center of the image, instead of the center of the stage.... how to keep the image can be enlarged from the center stage not from center image ?

}

Upvotes: 1

Views: 96

Answers (1)

dikagaulzzz
dikagaulzzz

Reputation: 91

This is my simple code..

zoomin.addEventListener(MouseEvent.CLICK, f_zoomin);
function f_zoomin(e:MouseEvent)
{
    zoom = 1;
    f_zoom();
}
zoomout.addEventListener(MouseEvent.CLICK, f_zoomout);
function f_zoomout(e:MouseEvent)
{
    zoom = -1;
    f_zoom();
}
function f_zoom()
{
    var coord:Point = map.globalToLocal(new Point(stage.stageWidth/2, stage.stageHeight/2));
    map.scaleX += zoom;
    map.scaleY += zoom;
    map.x = ((2 * stage.stageWidth/2) - (2 * (coord.x * map.scaleX))) / 2;
    map.y = ((2 * stage.stageHeight/2) - (2 * (coord.y * map.scaleY))) / 2;
}

Btw your pic like my girlfriend.. LOL :D

Upvotes: 1

Related Questions