Questo è quello che ho fatto per cliccare il primo bottone creato in automatico
codice:
function caricato(evento:Event){
myXML = new XML(evento.target.data);
var figli:XMLList = myXML.child("img");
//metto i bottoni sx e dx sotto al ciclo for li posiziono
var sx:Sx = new Sx();
var dx:Dx = new Dx();
sx.name="sx";
dx.name="dx";
sx.alpha=0;
dx.alpha=0;
sx.mouseChildren=false;
dx.mouseChildren=false;
bottoni.addChild(dx);
bottoni.addChild(sx);
for (var i:int=0;i<figli.length();i++){
var bottone:MovieClip = new Bottone() as MovieClip;
bottone.mouseChildren=false;
bottone.buttonMode=true;
bottone.txtNumero.autoSize="left";
bottone.txtNumero.y = Math.round((bottone.height-bottone.txtNumero.height)/2)
bottone.txtNumero.x = Math.round((bottone.width-bottone.txtNumero.width)/2)
bottone.txtNumero.text = "0" + (i+1);
bottone.x = bottone.width*i;
bottoni.addChild(bottone);
TweenLite.from(bottone, .5, {alpha:0, delay:.15*(i+1)})
//leggo i dati del nodo e li metto nel bottone
var nodo:XML = new XML(figli[i]);
bottone.big = nodo.attribute("big");
bottone.small = nodo.attribute("small");
bottone.ita = nodo.attribute("ita");
bottone.eng = nodo.attribute("eng");
bottone.align = nodo.attribute("align");
bottone.strX = nodo.attribute("x");
bottone.strY = nodo.attribute("y");
bottone.i = i;
bottone.name = "bt"+i;
//listner
bottone.addEventListener(MouseEvent.CLICK, clickBottone);
bottone.addEventListener(MouseEvent.MOUSE_OVER, over);
bottone.addEventListener(MouseEvent.MOUSE_OUT, out);
if (i==0){
bottone.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
bottone.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
}
sarebbe più carino metterlo fuori dal ciclo ma funziona, per capirci