Feb
04
2009
[AS3] Scaling Sprite Containing TextField – Problem
Posted by SikoTiko in Problems, tags: actionscript 3, problem, scaling textfieldToday I run into this strange problem while trying to scale a Sprite containing dynamic TextField. As you can see in the flash demo below, when you scale the Sprite the TextField retains its position in the Sprite container.
This is the code that I use for scaling:
var testTxt:TextField = btn.getChildByName("labelTxt") as TextField; testTxt.autoSize = TextFieldAutoSize.LEFT; testTxt.text = "SCALE SPRITE+TXT"; testTxt.x = 4; var bg:Sprite = btn.getChildByName("bg") as Sprite; bg.width = testTxt.width + 8; var orig:Sprite = new Test(); var txt:TextField = orig.getChildByName("labelTxt") as TextField; txt.autoSize = TextFieldAutoSize.LEFT; txt.text = "SCALE SPRITE+TXT"; txt.x = 4; var bg2:Sprite = orig.getChildByName("bg") as Sprite; bg2.width = txt.width + 8; orig.x = btn.x; orig.y = btn.y + btn.height + 4; addChild(orig); btn.scaleX = 100/btn.width;
And THE SOLUTION is to use GridFitType.NONE for the gridFitType property of the TextField. The default value of the gridFitType property is GridFitType.PIXEL, which forces the text field to position according to the grid.









Entries (RSS)
Very useful, thanks – I thought 9slice scaling would solve this problem, but I guess gridFitType property is the way to go
I haven’t tested it with 9slice scaling, but I don’t think it will work with the 9slice, because this is dynamic text and it is positioned according to the grid for a better readability. But I will try with 9slice scaling and will post the result.