정말 도움 이해를 필요, 난 그냥 알아낼 수 없습니다 :TextField가 DisplayContainer의 하위가 아닌 스테이지에 표시됩니까? 이 영향을 미치는 이유</p> <pre><code>textFields[i].text = thisWord.charAt(i); </code></pre> <p>나는 그것이 특정 인덱스에 값을 업데이트 이해 한 후 세드릭
textContainer.addChild(tempText);
textFields.push(tempText);
값을 그 변경되면 무대에 표시되지만 텍스트 콘테이너의 자식으로 추가 된 적이 없기 때문에 이유를 알 수 없습니다.
var loader:URLLoader;
var allWords:Array;
var thisWord:String;
var textContainer:MovieClip;
var textFields:Array;
var textStyle:TextFormat;
var underline:MovieClip;
function init():void
{
loader = new URLLoader();
allWords = new Array();
textContainer = new MovieClip();
textFields = new Array();
textStyle = new TextFormat();
textStyle.font = "Courier New";
textStyle.size = 48;
textStyle.bold = true;
textContainer.y = stage.stageHeight/2 - 50;
addChild(textContainer);
loader.load(new URLRequest("words.txt"));
loader.addEventListener(Event.COMPLETE, textLoaded);
guess_btn.addEventListener(MouseEvent.CLICK, guess);
}
function textLoaded(event:Event):void
{
var tempText:TextField;
var stringOfWords:String = event.target.data;
allWords = stringOfWords.split(",");
thisWord = allWords[Math.floor(Math.random() * allWords.length)];
trace(thisWord);
for (var i:uint = 0; i < thisWord.length; i++)
{
tempText = new TextField();
tempText.defaultTextFormat = textStyle;
tempText.name = "textField" + i;
tempText.text = "1";//for restart
tempText.width = 48;
tempText.x = i * tempText.width;
tempText.selectable = false;
textContainer.addChild(tempText);
textFields.push(tempText);
if (thisWord.charAt(i) != " ")
{
underline = new Underline();
underline.x = tempText.x + tempText.width/3;
underline.y = tempText.y + tempText.height/2 + 5;
//textContainer.addChild(underline);
}
}
textContainer.x = stage.stageWidth/2 - textContainer.width/2;
}
function guess(event:MouseEvent):void
{
if (guess_txt.text != "")
{
if (thisWord.indexOf(guess_txt.text) != -1)
{
for (var i:uint = 0; i < textFields.length; i++)
{
if (thisWord.charAt(i) == guess_txt.text)
{
textFields[i].text = thisWord.charAt(i);
trace(textFields[i].text);
}
}
}
else if (guesses_txt.text == "")
{
guesses_txt.appendText(guess_txt.text);
}
else
{
guesses_txt.appendText("," + guess_txt.text);
}
}
guess_txt.text = "";
findch();
}
init();
나는 확신 프로그래머에게 내가 없거나 이해하고 있지 않다 규칙 ....
감사 해요.
빠른 답장을 보내 주셔서 감사합니다. 아직 생각하지 않고 있습니다.//. 무대에 나타나는 것이 "tempText"개체가 textContainer에 추가 된 경우 ... "textFields"의 인덱스를 변경하면 tempText의 값이 변경되는 이유는 무엇입니까? – aph107
"재 할당"하는 코드가 없습니다. textFields [i] .text = thisWord.charAt (i); "tempText"로 – aph107
나는 거대한 "OH"순간을 보내고있다. 나는 그 생각 textFields.push (tempText); 실제 개체가 아닌 "값"을 배열에 넣었고 textFields [i] .text = thisWord.charAt (i); 값을 변경했지만 무대에 추가하지 않았습니다. 실제로 그것은 무대에 이미 있던 물체를 변경하고있었습니다. 다른 방법으로 나에게 반복 할 사람이 필요하다고 생각합니다. 내가 미쳤다고 생각 했어. 감사. – aph107