
Copy link to clipboard
Copied
I have this code
for (var i = 0; i < levelbtns.length; i++) {
if (event.currentTarget== levelbtns) {
}
levelbtns contains a whole heap of buttons
It requires the name check because the resulting action depends on a few variables that i need the button name to know.
I’m getting the error of
1120: Access of undefined property event.
Thanks
1 Correct answer
If you do not have that "event" defined as an incoming argument of the function that contains that code then targeting it is not going to work. The usual scenario for something like you appear to want would be first having event listeners assigned to the buttons, then having the event handler function checking for which button was clicked.
for (var i = 0; i < levelbtns.length; i++) {
levelbtns.addEventListener(MouseEvent.CLICK, clicked);
}
function clicked(event:MouseEvent):void {
var
...Copy link to clipboard
Copied
If you do not have that "event" defined as an incoming argument of the function that contains that code then targeting it is not going to work. The usual scenario for something like you appear to want would be first having event listeners assigned to the buttons, then having the event handler function checking for which button was clicked.
for (var i = 0; i < levelbtns.length; i++) {
levelbtns.addEventListener(MouseEvent.CLICK, clicked);
}
function clicked(event:MouseEvent):void {
var btnName:String = event.currentTarget.name;
}
Note that you do not need to loop thru all the buttons to get the button name. The event.currentTarget gives you a direct line of sight as to which button was clicked.

