我在ActionScript中構建一個Facebook客戶端,和我遇到的一個問題。我有這個代碼塊:與TextField的只顯示最後一個AS3的addChild添加
var loader:URLLoader = URLLoader(event.target);
var feedResponse:String = (event.target.data);
var object:Object = JSON.decode(feedResponse); //getting the data
var friendsStatus:Array = new Array(); //array for status'
var friendsName:Array = new Array(); //array for names
var startX:int = 120;
var startY:int = 100;
var myFormat:TextFormat = new TextFormat();
myFormat.size = 16;
var statusMessage:TextField = new TextField();
statusMessage.defaultTextFormat = myFormat;
statusMessage.wordWrap = true;
statusMessage.width = 600;
var faceFriend:TextField = new TextField();
faceFriend.defaultTextFormat = myFormat;
faceFriend.wordWrap = true;
faceFriend.width = 300;
for(var i:int = 0; i < 10; i++)
{
if(object.data[i].message == undefined){
var userStory:String = object.data[i].story; // mowing through the facebook JSON response
friendsStatus[i] = userStory;
} else {
var userStatus:String = object.data[i].message;
friendsStatus[i] = userStatus;
}
var fName:String = object.data[i].from.name;
friendsName[i] = fName;
}
for(var j:int; j < 10; j++) // The headache loop
{
faceFriend.x = startX;
faceFriend.y = startY;
faceFriend.text = friendsName[j]; //assign the current name to the TextField text property
addChild(faceFriend); //add it to the stage
startY += 30; //increase the y value so they dont overlap
trace(startY);
trace(faceFriend.text);
trace("");
statusMessage.x = startX;
statusMessage.y = startY;
statusMessage.text = friendsStatus[j]; //same here for the status'
addChild(statusMessage);
startY += 20;
trace(startY);
trace(statusMessage.text);
trace("");
}
它通過一組的狀態應該循環,並將其分配給變量並將其添加到舞臺上。然而,我所獲得的只是最後一個加入舞臺的地位。 正如你可以從所有的痕跡中看到的,我發現所有的數組都有正確的信息,並且y值(所以它不是全部在另一個之上)正在正確地進展。它只是拒絕讓任何東西,但最終的文本字段可見:(
任何想法
PS我意識到這不是正是輝煌的代碼 - 遺憾的頭痛提前:P
哇,太感謝你了傢伙,這固定我的問題:)不能相信我沒想到的吧! – user1027657