Event listener get "this" but it returns class

I have a function that adds these textfields that act like “buttons” (there can be up to infinate amount of them) and I add a listener for “MOUSE_DOWN” and in the mousedown function I try to use “this.text” but it errors saying “myClass has no field text” how can i get this(as in this textfield/button) because I do not know how many of them there would be so I cannot store them in a var and array would not be efficient.

It is normal that it says “myClass has no field text”, because this referes to the class and nothing else.
I have an idea of what you need but I have never tried it with a textField but it should work just fine.

function mouseDown(e:MouseEvent){
if(Std.is(e.target,TextField){ //just making sure you really clicked on a textfield and nothing else
var t:TextField = e.target; // from here on t is the textField you have clicked on.

Thank you I was sure there was an easy way to do it.

Yeah, this is a subtle difference between closures in Haxe and a language like JavaScript, “this” will always refer to the current class instance, and does not change scope within a listener. Most of the time, this is a great thing :smiley: