I have a class that I made to control all my buttons from a centralized location. The buttons are pushed into an array on load and a for loop adds a MouseEvent.CLICK event listener to all the buttons in the array.
Now my problem comes in with the function tied to this event listener. I have created a switch statement
function btnclick(e:MouseEvent):void
{
switch (e.currentTarget)
{
case Profile_btn_63 :
removearrayreference(this);
e.currentTarget.parent.gotoAndStop("profile");
break;
}
}
but the problem is when I test the game it states Profile_btn_63 is undefined. Which is actually true at the very beginning(first frame) as the button hasn’t been added to the button array yet nor has an event listener been placed on it. So to get to the point I need help with making flash ignore that Profile_btn_63 is undefined until it eventually does get defined.
Finally this may be somewhat off topic but does anyone know why _63 is added to the end of Profile_btn when it is pushed into my button array?
If you’re going to have a “magic switch statement” that does everything in your program – which is a horrible idea in more than one way, but that is a different matter – then you should make the
casedecisions based on the instance name:switch( e.currentTarget.name )While a button instance may be
nullorundefined, a constant String never is.