Skip to main content
noggin30
Known Participant
September 20, 2010
Answered

How to scale from the middle in Actionscript

  • September 20, 2010
  • 1 reply
  • 755 views

Hello all.

I have the following code:

function box1ScaleUp(e:MouseEvent):void {

box1.scaleX = 1.5;

box1.scaleY = 1.5;

box2.x = 80

box3.x = 135

}

Now, when it scales, it scales from the movieclip var registration point of 0,0. So when it scales, it appears to grow in two directions (down and to the right)

Is there a way to have it scale from the center of the box so that it scales equally in all 4 directions?

Thanks in advance!

This topic has been closed for replies.
Correct answer kglad

you can change your reg point to box1's center or you can add box1 to a parent and offset it and scale its parent:

var p:MovieClip=new MovieClip();

box1.parent.addChild(p)

p.x=box1.x+box1.width/2;

p.y=box1.y+box1.height/2;

box1.x=-box1.width/2;

box2.y=-box1.height/2;

p.addChild(box1);

p.scaleX=1.5;

p.scaleY=1.5;

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 20, 2010

you can change your reg point to box1's center or you can add box1 to a parent and offset it and scale its parent:

var p:MovieClip=new MovieClip();

box1.parent.addChild(p)

p.x=box1.x+box1.width/2;

p.y=box1.y+box1.height/2;

box1.x=-box1.width/2;

box2.y=-box1.height/2;

p.addChild(box1);

p.scaleX=1.5;

p.scaleY=1.5;

noggin30
noggin30Author
Known Participant
September 20, 2010

Thanks!

Haha, I totally didn't think of changing the reg point in the symbol. DUH!

kglad
Community Expert
Community Expert
September 21, 2010

you're welcome.