Center zoom in flash

I am using flash (AS3) and have a dynamic clip that I want to scale up or down with the slider. I work very well using the scaleX and scaleY functions.

The only problem is that these scales are on the left side of the document, and I would like it to be scaled from the center.

Any help is appreciated.

+4
source share
3 answers
function scaleFromCenter(dis:*, sX:Number, sY:Number):void { var prevW:Number = dis.width; var prevH:Number = dis.height; dis.scaleX = sX; dis.scaleY = sY; dis.x += (prevW - dis.width) / 2; dis.y += (prevH - dis.height) / 2; } scaleFromCenter(yourMovieClip, 0.3, 0.3); 

..

Or look at Greensocks TweenMax / AutoFitArea

http://www.greensock.com/autofitarea/

Very powerful and easy to use.

+3
source

To scale / rotate from the center of the object, you need to do the following

  • Translate the object to 0.0.
  • Scale / Rotate
  • Translate it back to the original x, y.

Here is a piece of code that does this.

 private function scaleInPosition(dis:Sprite,sX:Number,sY:Number):void { var posX:Number = dis.x; var posY:Number = dis.y; dis.x =dis.y = 0; dis.scaleX = sX; dis.scaleY = sY; dis.x = posX; dis.y = posY; } 
+2
source

Just create an object that you scale with the 0.0 registration crosshair in the center.

+1
source

Source: https://habr.com/ru/post/1387185/


All Articles