I am using the following code in a program:
It is a simple conditional statement
in which a button moves to a certain group of frames when clicked depending on its current frame. This is the code I'm using.
var group1:Array=["b1","b2","b3"];
var group2:Array=["b12","b22","b32"]
mainbutton.addEventListener(MouseEvent.CLICK, buttonflash)
function buttonFlash (e:MouseEvent)
{
for (var gr1:uint=0; gr1<group1.length; group1++)
{if
(e.target.currentLabel == group1[gr1])
{e.target.gotoAndStop(e.target.currentLabel + "2")}
else
{e.target.gotoAndStop(e.target.currentLabel.slice(0,2))}
}
}
However, when I include the for loop in the function, it causes the function to run the number
of times of the variable. In testing, I switched out the else statement with a trace string and the string showed up in the output window three times.
When I place the for loop outside of the function, the output compiler says the variable is undefined. Any ideas as to what I'm doing wrong to have the loop run once?
var group1:Array=["b1","b2","b3"];
var group2:Array=["b12","b22","b32"]
mainbutton.addEventListener(MouseEvent.CLICK, buttonflash)
function buttonFlash (e:MouseEvent)
{
for (var gr1:uint=0; gr1<group1.length; group1++)
{if
(e.target.currentLabel == group1[gr1])
{e.target.gotoAndStop(e.target.currentLabel + "2");
break;
}
else
{e.target.gotoAndStop(e.target.currentLabel.slice(0,2))}
}
}
Thanks for the reply!
This is closer than I've been able to get on my own, but there's still a slight problem. The else statement
still traces three times, so that prevents the second and third items in the array from working. So any button that is on frame label "b1" can go to "b12" and back to "b1", but if a button is on any other label it won't work. Any suggestions on how to fix this? Thanks in advance!
var group1:Array=["b1","b2","b3"];
var group2:Array=["b12","b22","b32"]
var isInGroup:Boolean=false;
mainbutton.addEventListener(MouseEvent.CLICK, buttonflash)
function buttonFlash (e:MouseEvent)
{
for (var gr1:int=0; gr1<group1.length; gr1++) //Thank you Ned
{if
(e.target.currentLabel == group1[gr1])
{e.target.gotoAndStop(e.target.currentLabel + "2");
isInGroup=true;
break;
}
}
if (!isInGroup)
{e.target.gotoAndStop(e.target.currentLabel.slice(0,2))
isInGroup=false;
}
}
North America
Europe, Middle East and Africa
Asia Pacific