텍스트 필드의 진실
ActionScript 3 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)
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이 될 줄 알고 있었다는 것...
'ActionScript 3' 카테고리의 다른 글
단순 실험 2 - for vs while, ++ vs +1 (0) | 2009.03.02 |
---|---|
단순 실험 1 - addChild VS addChildAt (0) | 2009.03.02 |
Timer class 의 Timer 생성자의 delay 인수 데이터 타입 에러... (0) | 2008.04.04 |
[강좌] AS3.0 의 XML 을 이용한 작업 (4) | 2008.01.17 |
[강좌] AS3.0 의 Document Class 를 이용한 작업 (0) | 2008.01.17 |