flash actionscript:
Hello, I'm making dinamic buttons using an array and one for in loop. Everything works great, except this, I've this produtos = new Array(agricultura,ambiente,comercio,construcao) then using the for in command I create empty movie clips and in each one textfield. Now I need to make my btn[k]["mytext"[k]].text = "one of those words in the array" How do I make this? Thanks for help :-)
To acess an value in a array: my_button_text = my_array[k];
Make sure that your array is declared correctly... it should probably be holding STRING values not as you have declared it ... try : produtos = new Array("agricultura","ambiente","comercio","construcao"); for(var k=0; k< produtos.length; k++){ this.attachMovie("btnImage","btn_"+ k,k); this["btn_"+ k]._x = 40; this["btn_"+ k]._y = 40 + (40*k); this["btn_"+ k].btn_txt.text = produtos[k]; this["btn_"+ k].onRelease = function(){ trace(this._name + " is the button and " + this.btn_txt.text + " is the text on the button"); } } cheers,
Hello, and thanks for help! Well, yes, it surelly works as you both said, it was indeed simple! Just one thing, I'm creating 11 buttons at once, but my code has some error I can't find, please just copy paste this and see that the first button is not where he should be, at _y = 137. Can you point me in the right direction to make this work? Thanks! r = _root; e = this; function listar_familias() { //produtos = new Array(l_familias.vars); produtos = new Array("Agricultura, Silvicultura e Pesca", "Ambiente", "Com?rcio", "Constru??o Civil / Obras P?blicas", "Hotelaria e Restaura??o", "Protec??o Civil", "Fabrica??o e Manuten??o", "Saneamento e Limpeza", "Saude e Medicina", "Servi?os", "Transportes"); for (i=0; i<produtos.length; i++) { r.createEmptyMovieClip("btn_"+i, 20+i); r["btn_"+i].beginFill(0xC7C0C0, 50); r["btn_"+i].lineStyle(0.25, 0xFFFFFF, 100); r["btn_"+i].lineTo(0, 20); r["btn_"+i].lineTo(300, 20); r["btn_"+i].lineTo(300, 0); r["btn_"+i].lineTo(0, 0); r["btn_"+i].endFill(); r["btn_"+i]._x = 141.8; if (i == 1) { r["btn_"+i]._y = 137; } else { //r["btn_"+i]._y = 137+(30*i); r["btn_"+i]._y = r["btn_"+(i-1)]._y+r["btn_"+(i-1)]._height+10; } r["btn_"+i].createTextField("familias"+i, e+1, 0, 0, 298, 20); r["btn_"+i]["familias"+i].text = produtos; r["btn_"+i]["familias"+i].embedFonts = true; r["btn_"+i]["familias"+i].tabEnabled = false; r.btn_1.familias1.setTextFormat(f_btn); r.btn_2.familias2.setTextFormat(f_btn); r.btn_3.familias3.setTextFormat(f_btn); r.btn_4.familias4.setTextFormat(f_btn); r.btn_5.familias5.setTextFormat(f_btn); r.btn_6.familias6.setTextFormat(f_btn); r.btn_7.familias7.setTextFormat(f_btn); r.btn_8.familias8.setTextFormat(f_btn); r.btn_9.familias9.setTextFormat(f_btn); r.btn_10.familias10.setTextFormat(f_btn); r.btn_11.familias11.setTextFormat(f_btn); } r.btn_1.onRollOver = function() { trace("ol?"); }; } listar_familias();
If you are talking about the position of the first button ... then that is simple... the first time through the loop, the value isn't 1 it is 0, so that means your condition of : if(i == 1) isn't going to be correct... i = 0; cheers,
Oh boy, I can't believe it, so simple.
Don't see what you're looking for? Try a search.
|