Today 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.

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

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.

  • Share/Bookmark
2 Responses to “[AS3] Scaling Sprite Containing TextField – Problem”
  1. Flanture says:

    Very useful, thanks – I thought 9slice scaling would solve this problem, but I guess gridFitType property is the way to go

  2. SikoTiko says:

    I haven’t tested it with 9slice scaling, but I don’t htink 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.

  3.  
Leave a Reply


TxEff - The Flash Text Effects