scaleform.minarto.com

텍스트 필드의 진실 본문

ActionScript

텍스트 필드의 진실

미나토 2008. 6. 9. 15:15


실로 오랜만의 포스팅.... 먹고 살기 바쁘다 보니...

회사 녀석이 물어본 볼드체(또는 이탤릭체) 끝이 잘려버리는 현상을 설명해주기 위해 만든 테스트 코드...


var textFormat:TextFormat = new TextFormat("굴림", 12, 0, false, true);

var txt:TextField = new TextField();
addChild(txt);
txt.border = true;
txt.text = "DSfasfsaf";
txt.autoSize = TextFieldAutoSize.LEFT;
txt.setTextFormat(textFormat);
graphics.lineStyle(1, 0, .2)
graphics.drawRect(txt.x + (txt.width - txt.textWidth) / 2, txt.y + (txt.height - txt.textHeight) / 2, txt.textWidth, txt.textHeight)
trace(txt.height, txt.textHeight)


txt = new TextField();
addChild(txt);
txt.y = 20;
txt.text = "DSfasfsaf";

txt.setTextFormat(textFormat);
txt.autoSize = TextFieldAutoSize.LEFT;
txt.border = true;
trace(txt.width, txt.height)
txt.autoSize = TextFieldAutoSize.NONE;
trace(txt.width, txt.height)
txt.width += (txt.width - txt.textWidth) / 2;
txt.height += (txt.height - txt.textHeight) / 2;
graphics.lineStyle(1, 0, .2)
graphics.drawRect(txt.x + (txt.width - txt.textWidth) / 2, txt.y + (txt.height - txt.textHeight) / 2, txt.textWidth, txt.textHeight)

trace(txt.width, txt.height)


생각한 것과는 다른 결과가 나올 것이다


한가지 내가 잘못 알고 있었던 것은

txt.autoSize = TextFieldAutoSize.NONE

이러면 텍스트 필드의 width, height 가 0이 될 줄 알고 있었다는 것...