Sto studiando questa funzione spettacolare per creare dinamicamente dei bottoni.
Come potete vedere le scritte dei bottoni sono inserite in un array. E fin qui tutto bene.
Il problema sorge quando cerco di popolare l'array dinamicamente attraverso un onLoad: non funziona più niente. Non riesco a capire se tutto codice deve metterlo all'interno dell'onLoad oppure fuori. Eppure le scritte esterne vengono inserite nell'array correttamente. dhò:![]()
function createButton(name, where, depth, x, y, width, height, text, color)
{
var mc = where.createEmptyMovieClip(prova, depth);
mc._x = x;
mc._y = y;
mc.moveTo(0, 0);
mc.lineStyle(1, 0x000000, 100);
mc.beginFill(color, 100);
mc.lineTo(width, 0);
mc.lineTo(width, height);
mc.lineTo(0, height);
mc.lineTo(0, 0);
mc.endFill();
mc.createTextField("txt", 1, 0, 0, 1, 1);
mc.txt.autoSize = "left";
mc.txt.text = text;
mc.txt._x = Math.round((width / 2) - (mc.txt._width / 2));
mc.txt._y = Math.round((height/ 2) - (mc.txt._height/ 2));
var myformat = new TextFormat("Verdana", 14, 0x55CCCC);
mc.txt.setTextFormat(myformat);
return mc;
}
function init(){
var testi = ["primo pulsante", "secondo pulsante", "terzo pulsante"];
var colori = [0xFFCC00, 0x00CC99, 0xFF00FF];
for(var i = 0; i < testi.length; i++){
var profondita = i;
var nome = "pulsante" + i;
var posizione = 140 * i;
var but = createButton(nome, this, profondita, posizione, 50, 130, 25, testi[i], colori[i]);
but.testo = testi[i];
but.onRelease = function(){
trace(this.testo)
};
}
}
init();