This is driving me insane now.
I have a loop that creates buttons. Each button stays on the screen, but scrolls off, meaning there are at any one time upto 4 buttons on the screen. There are a total of 241 buttons.
It is to my understanding that using an array will allow me to access these buttons later, and that is great, but I can not find a way for it to tell me exactly which button was clicked.
Am I missing something very simple here?
if (canAdd == true)
{
canAdd = false;
while (curName < nextName)
{
var names:namez = new namez();
names.ID = curName;
names.name = "ID"+(curName);
mcArray[curName] = names;
names.t2.dtf_txt.text = getNames[curName];
names.y = -28;
spinner.addChild(names);
if (curName < nextName)
{
curName = nextName;
trace("curName updated to "+curName);
}
}
mcArray[curName - 1].addEventListener(MouseEvent.CLICK, checkMe);
}
timer.start();
}
public function checkMe(e:MouseEvent)
{
trace("you clicked " + e.target.name);
//trace("clicked: "+e.target.ID)
//var names:namez = e.target as namez;
//trace("clicked" + names.ID);
//trace("clicked"+namez.ID);
}
}
What exactly should be in checkMe?
As you can see I have tried all sorts – The namez class even has an ID internal variable within it, but calling that still just gives an error.
You should use e.currentTarget instead of e.target