2013-07-08 5 views
0

ActionScript 3에서 TextField을 동적으로 만들려고합니다. 아래 코드는 텍스트 상자 자체를 그립니다 (이 경우 빨간색 사각형 임). "Add text here" 문자열이 표시되지 않습니다. . 이 문제를 해결하려면 어떻게해야합니까?표시 할 TextField에 텍스트를 가져올 수 없습니다.

var d:Number = mc.getNextHighestDepth(); 

var x:Number = (screenWidth - boxWidth)/2; 
var y:Number = (screenHeight - boxHeight)/2; 

var w:Number = boxWidth; 
var h:Number = boxHeight; 

notification = mc.createTextField("Text", d, x, y, w, h); 
notification.background = true; 
notification.backgroundColor = 0xFF0000; 
notification.selectable = false; 
notification.wordWrap = true; 
notification.text = "Add text here"; 
+1

'TextField'에 설정 한 글꼴을 포함 시켰는지 확인하십시오. 'TextFormat' 객체를'TextField'의'defaultTextFormat' 속성에 할당하고 글꼴을 변경할 때'TextField'의'setTextFormat (format)'메소드를 호출합니다. 'mc.createTextField' 메소드 소스를 게시하면 도움이 될 것입니다. 우리가 실제로 당신이하는 일을 볼 수 없기 때문입니다. @Discipol이 답변 한대로, 당신은 또한 어떤 종류의'DisplayObject'를'DisplayList'에 추가하여 그것을 보이게 할 필요가있을 것입니다, 그러나 빨간 사각형이 그려진다면 당신은 이미 그것을 추가했다고 가정합니다. – Gio

+0

'ms.creatyeTextField'의 소스를 게시한다는 것은 무엇을 의미합니까? 표준 [MovieClip.createTextField] (http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001286.html) 메소드입니다. –

+0

아, 죄송합니다. 실제로 AS2 API를 사용하고 있으며 'MovieClip'이라는 하위 클래스가 있다고 생각할 수 없습니다. 그래서 Actionscript 3에서는'TextField'를 그렇게 만들지 않습니다. AS3에서'TextField'를 만드는 올바른 방법은 다음과 같습니다 :'var tf : TextField = new TextField();' 그런 다음 이것을 부모 DisplayObjectContainer에 자식으로 추가하고 필요할 경우'TextFormat'을 설정하십시오. – Gio

답변

1

textField가 표시 목록에 추가되도록 addChild (알림)를 수행해야합니다.

관련 문제