0
所以我做了一個對象數組像這樣的(?):我如何通過這個對象遍歷正確AS3
public var object:Object =
{
"part1" : {
"text" : "Your name is Richard, a 20-something year old construction worker who just returned home from a night of heavy drinking. The clock above your sofa reads 9:37PM. What do you do?",
"choices" : {
"response1" : {
"text" : "Go to sleep",
"nextPart" : "part2"
},
"response2" : {
"text" : "Watch TV",
"nextPart" : "part3"
}
}
},
"part2" : {
"text" : "You go to sleep. You are awoken by the sound of glass smashing outside your house. The time on your alarm reads 12:30AM",
"nextPart" : "part3"
},
"part3" : {
"text" : "You sit down and start watching TV. All channels seem to be the same thing, a breaking news report. You tune in.",
"nextPart" : "part4"
},
"part4" :
{
"text" : "The reporter on the screen has a panicked tone, which you seem to think is unprofessional. You are horrified by what you hear; people are turning into disgusting deformed mutants that possess super human abilities. You are interrupted by someone jumping through your front window. How rude.",
"nextPart" : "part5"
},
"part5" : {
"text" : "You get up from your sofa and go towards the dickhead who jumped through your window. He turns out to be a dead body that was acutally thrown through the window. He's missing an eye and large portion of his skull. You look up to see a disfigured man standing outside your window. His face has swollen to 3x it's original size and covers his neck. He climbs through your window. You noticed acidic green liquid dripping from orifices on his face.",
"nextPart" : "part6"
}
}
我需要通過part1
的選擇進行迭代。
我目前正在此:
for (var s:String in object[curPart]["choices"]) i++
{
trace(i)
textFinished = false
var txt:TextField = new TextField();
txt.defaultTextFormat = new TextFormat('Verdana',15,0xFFFFFF);
txt.text = String(i)
txt.filters = [stroke];
txt.autoSize = TextFieldAutoSize.LEFT;
txt.selectable = false;
txt.width = 400
txt.height = 25
var btn:Sprite = new Sprite();
btn.mouseChildren = false;
btn.addChild(txt);
btn.buttonMode = true;
btn.x = stage.stageWidth/10
btn.y = stage.stageHeight/2 - 50 * (i * .5)
btn.name = "part" + String((Number(Number(curPart.substring(4))+1) + (i+1)))
buttonHolder.addChild(btn);
btn.addEventListener(
MouseEvent.CLICK,
function m(zen:MouseEvent):void // when button is clicked
{
//trace(buttonHolder.numChildren)
//choice(zen.currentTarget.name,buttonHolder);
}
)
// Each button is put in the list,
// to be able to work with the button after
}
,但我只拿到1個文本框和說2(即使有應該是去1 2個文本字段,2)
請在此處顯示您的代碼,而不是在將來可能會消失的其他地方 – frankhermes