as3 TWEEN-ing to a equal proportion?

207 Views Asked by At

Here is the code to make an MC the exact size in even proportions of whatever your choice. I choose 777 for this example.

my_mc.height = 777; // Can be anything you want. 
my_mc.scaleX = my_mc.scaleY; /// This makes it the same proportions.

Now the questions is how can I tween this?

2

There are 2 best solutions below

0
On

I'm afraid you have to tween both x and y scale values.

Other scenarios can be tricky.

Another alternative would be to tween an arbitary property of the movieclip, and letting a frame-based function (called on ENTER_FRAME event) that reads this variable and updates both scale values.

OR, making a custom movieclip class and let its internals handle a custom scaleXY property.

0
On
function tweenThis(newHeight:uint):void{
    var oldHeight:uint=my_mc.height;
    var difValue:Number=newHeight/oldHeight;
    var newWidth:uint=my_mc.width*difValue;
    new Gtween(my_mc,1,{width:newWidth,height:newHeight});
}