actionscript 3 - Loop only showing the last array element ActionScript3 -
this actionscript3 code made 2 text fields , assign them textformats, , 2 array. want value of array in new text field each iteration of loop.but showing lastly element value of array.i think there problem y position.thanks in advance.
var heading:array = ["home","about","services","contact"]; var subheading:array = ["mydata","aboutus","servicesprovided","contactus"]; var i:int = 0; var j:int = 0; var headformat:textformat = new textformat(); headformat.size = 20; headformat.color = 0xffffff; headformat.align = textformatalign.center; var subformat:textformat = new textformat(); subformat.size = 15; subformat.color = 0x000000; subformat.align = textformatalign.center; var headtext:textfield = new textfield(); headtext.width = 200; headtext.text headtext.height = 50; headtext.background = true; headtext.defaulttextformat = headformat; headtext.backgroundcolor = 0x0000ff; var subtext:textfield = new textfield(); subtext.width = 200; subtext.height = 50; subtext.background = true; subtext.backgroundcolor = 0xcccccc; subtext.defaulttextformat = subformat; for(i=0;i<heading.length;i++) { headtext.text = heading[i]; headtext.y = j; addchild(headtext); j+= 60; subtext.text = subheading[i]; subtext.y = j; addchild(subtext); j+=60; }
the problem utilize same instance of text boxes set creation of text boxes loop, each iteration create instance of text box.
var headtext:textfield; var subtext:textfield; for(i=0;i<heading.length;i++) { headtext = new textfield(); headtext.width = 200; headtext.text headtext.height = 50; headtext.background = true; headtext.defaulttextformat = headformat; headtext.backgroundcolor = 0x0000ff; subtext = new textfield(); subtext.width = 200; subtext.height = 50; subtext.background = true; subtext.backgroundcolor = 0xcccccc; subtext.defaulttextformat = subformat; headtext.text = heading[i]; headtext.y = j; addchild(headtext); j+= 60; subtext.text = subheading[i]; subtext.y = j; addchild(subtext); j+=60; }
actionscript-3
No comments:
Post a Comment