问题
I need to scale a dynamic text box from it's center point using Tween class AS3.
Basically, I need to scale down to 50% in 300ms or so... and after finish I want to scale up again to 100% and stop animation.
I tried to set the center point to the center of the text box but it always scale from left.
Well I been trying hard to learn the basics of Tween class and I believe it's missing some good properties and methods like greensock!
Thank you.
title_txt.text = "Text";
var textScaleX:Tween;
var textScaleY:Tween;
title_txt.addEventListener(MouseEvent.MOUSE_OVER, scaleObj(1,2, 1));
function scaleObj(startUp:int, endUp:int, duration:int){
textScaleX = new Tween(title_txt, "scaleX", Strong.easeInOut, startUp, endUp, duration, true);
textScaleY = new Tween(title_txt, "scaleY", Strong.easeInOut, startUp, endUp, duration, true);
}
回答1:
The oringin of a textfield will alwasy be in the top left corner. You could however calculate where the top left corner would be at 50% of the scale and the tween the x and y postion along with the scaleX and scaleY values.
A quick calculation of the 50% x and y would be something like:
50% x = 100% x position + (100% textfield width)/4
50% y = 100% y position + (100% textfield height)/4
Edit: Here is how this calculation in code would look like:
var targetScale:Number = .5; //scale 50% but any other scale would work here as well
var targetX:Number = title_txt.x + (title_txt.width - title_txt.width * targetScale) / 2;
var targetY:Number = title_txt.y + (title_txt.height - title_txt.height * targetScale) / 2;
I use my own tween class so I'm not sure how to implement this with either the Adobe tween class or the TweenLite class, but if you stick these numbers in any tween class the textfield (or any object with it's origin in the top left corner for that matter) will scale around is center point.
回答2:
Number 1 tip for tweening:
- Don't use adobe tweening classes: their functionalities are not good enough.
Use TweenLite: it's easier to use and has more features.
I realise it's not really an answer to your question, but others have already covered that.
来源:https://stackoverflow.com/questions/13885485/scale-from-center-point-with-tween-class-as3