Take the 2-minute tour ×

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);
share|improve this question
Put the text field in a movie clip and center the text field in the movie clip..then tween that movie clip rather than the text field –  Ronnie Dec 14 '12 at 20:53
Ok i understand but than I have a problem, the text of the text field comes from a xml and is assigned inside of a for loop like this: for(...){this.["textbox"+0] = list.parent.child.text()[i];} how can I assign the list text value to the movie clip within the for loop? for(...){this.["mcname"+i]} till here no problem but how can i reach the text field inside the movie clip inside the for loop? –  FCC-PT Dec 14 '12 at 23:46
add comment

2 Answers

Number 1 tip for tweening - NEVER use the adobe tweening classes; they stink.

Stick with TweenLite - its easier to use and has more features.

I realise it's not really an answer to your question, but others have already covered that ;)

share|improve this answer
Thank you very much for your help. But I really can't find a solution for this. I understand that tweenmax has a method to scale from center but I can't afford it. I've also tried to add the text field as a child of sprite changed the registration point of the sprite and still scales from left :( –  FCC-PT Dec 14 '12 at 23:37
add comment

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.

share|improve this answer
Can you give me a real example with AS3 code? thank you very much for your help. –  FCC-PT Dec 14 '12 at 23:48
I put an example in the answer.. hope it helps. –  Arno van Oordt Dec 16 '12 at 11:37
add comment

Your Answer


