Esta es otra manera de hacerlo, dime q t parece:
Código ActionScript :
import flash.text.TextField;
import flash.display.MovieClip;
import DynamicSprite;
var spr02:Sprite=new Sprite;
var n:uint;
var st01:Array=new Array('yuxtaposició','pрпак','teclat','colom','arreboire',
'contingut','blau','rentadora','cadira','ratoli','jerro','id¶☺a','pare','teclat',
'malson','desgracia','finestra','taronja','caball','lampada','escacs','tintorera',
'ura','plati','esquema','llantia','mag','electro','cantar','rodona');
var textos:Array;
var formatoTexto:TextFormat=new TextFormat();
formatoTexto.color=0x000000;
formatoTexto.size=11;
formatoTexto.align='center';
formatoTexto.font='courier new';
formatoTexto.bold=false;
formatoTexto.color = 0x000000;
var x0:Number = 0;
var y0:Number = 0;
var filas:uint = 10;
var cont:uint = 0;
textos = new Array();
for (n = 0; n < st01.length; n++)
{
var txtContainer:DynamicSprite = new DynamicSprite();
var texto:TextField = new TextField();
texto.defaultTextFormat=formatoTexto;
texto.border=true;
texto.text = st01[n];
texto.width=220;
texto.height=20;
texto.background=true;
texto.backgroundColor=0xffffff;
texto.borderColor=0xf5f5f5;
textos.push(texto);
txtContainer.buttonMode=true;
txtContainer.mouseChildren=false;
txtContainer.addEventListener(MouseEvent.ROLL_OUT,out);
txtContainer.addEventListener(MouseEvent.ROLL_OVER,over);
txtContainer.addChild(texto);
txtContainer.x = x0;
txtContainer.y = y0;
txtContainer.id = n;
cont++;
if (cont == filas)
{
cont = 0;
x0 += 225;
y0 = 0;
} else
{
y0 += 20;
}
spr02.addChild(txtContainer);
}
addChild(spr02);
function over(evt:MouseEvent):void
{
textos[evt.target.id].backgroundColor = 0xf1f1f1;
}
function out(evt:MouseEvent):void
{
textos[evt.target.id].backgroundColor = 0xffffff;
}/**/
gracias a DynamicSprite podemos guardar un id en el sprite, y con el buscar el texto correspondiente en el array de textos.
Código ActionScript :
package {
import flash.display.Sprite;
public dynamic class DynamicSprite extends Sprite{
public function DynamicSprite()
{
}
}
}/**/
otra forma podria ser declarar a txtContainer como Movieclip, la clase MovieClip permite agregar nuevas variables en tiempo de ejecucion como lo hace DynamicSprite.
Código ActionScript :
var txtContainer:MovieClip = new MobieClip();