i have 20 text fields that i want to have mouse event listeners and their functions, can i use for loops to take care of them all? my code works for one of them, but then i tried using a for loop to do all of them and couldn’t. also, can buttonMode be applied to text fields in a simple way?
this code doesn’t work:
for(var i:int = 1; i <= 20; i++)
{
part*.addEventListener(MouseEvent.CLICK, goToFrame*);
part*.addEventListener(MouseEvent.ROLL_OVER, onOver*);
part*.addEventListener(MouseEvent.ROLL_OUT, onOut*);
}
for(var j:int = 1; i <= 20; j++)
{
function goToFrame[j](e:MouseEvent):void
{
part[j].removeEventListener(MouseEvent.ROLL_OVER, onOver[j]);
part[j].removeEventListener(MouseEvent.ROLL_OUT, onOut[j]);
this.gotoAndPlay("S" + [j]);
}
}
for(var k:int = 1; i <= 20; k++)
{
function onOver[k](e:MouseEvent):void
{
part[k].textColor = 0x0000FF;
}
}
for(var l:int = 1; i <= 20; l++)
{
function onOut[l](e:MouseEvent):void
{
part[l].textColor = 0x000000;
}
}
this code works:
part1.addEventListener(MouseEvent.CLICK, goToFrame1);
part1.addEventListener(MouseEvent.ROLL_OVER, onOver1);
part1.addEventListener(MouseEvent.ROLL_OUT, onOut1);
function goToFrame1(e:MouseEvent):void
{
part1.removeEventListener(MouseEvent.ROLL_OVER, onOver1);
part1.removeEventListener(MouseEvent.ROLL_OUT, onOut1);
gotoAndPlay("S1");
}
function onOver1(e:MouseEvent):void
{
part1.textColor = 0x0000FF;
}
function onOut1(e:MouseEvent):void
{
part1.textColor = 0x000000;
}