I have quite a few movieclip instances that needs an eventlistener that triggers on "click", and from a practical viewpoint, and also cpu resource-wise (If I've understood correctly). I don't want to assign separate listeners to each object.
Anyway, of course your code is erroring out, because arrays and strings don't have events.
If you really want to know how the browser event model works, here's one of many articles that gives a decent overview of the subject:
Thanks, you helped cleared things up quite a bit!
However I'm still confused as to how I should go about solving this properly.
The crux of my problem is; Is there a way to reuse a function called from the click-event and at the same time identifying which object was clicked?
hutB.on("click", listMyStuff.bind(this)); //instead of doing listMyStuffB()
hutC.on("click", listMyStuff.bind(this)); //instead of doing listMyStuffC()
function listMyStuff() //Superduper universal function that saves me from repeating it 20 times.
clickedObj=HutA, B or C etc. you just clicked;
firstTextfield = (populate with clickedObj index );
secondTextfield = (populate with clickedObj index );
- doing it like this always makes clickedObj be the last one given the eventlistener and listMyStuff() as they seem to override eachother chronologically.
Please forgive me if the answer is within the link you gave as I haven't had time to read through it properly yet.
When a click event handler is called, the two most important things to know are:
"this" is set to the DOM element that triggered the event.
The event handler executes in the global scope.
For example if you set an ID on the element, this.id in the event handler would retrieve it. You could then use this to determine which button had been clicked.
To deal with the scope issue, the easiest way is to set a global variable to the scope you'll need to access, like _mythis = this, then reference _mythis in the event handler.
Thanks once again!
I've been trying to fix this thing for hours on end, but I think your pinpointed answers helped more. Hopefully I will wrap my head around it tomorrow.