I have a major problem with event listeners and objects. This i a problem I've run into before, and I know there is a solution to it, but I have no idea what it is.
I have a class called Game, with lots of functions. One of those functions is a function called mouseDown, and in the constructor of the class I set an MC's onMouseDown listener to call the function mouseDown. The problem is that when the function is called, this refers to the MC, not the instance of the class.
Here is a simplified example:
When you run this, and click the screen, you will get the following trace:Code:var obj = { something : 4, mouseDown:function(){ trace(this); trace(something); } } trace(obj); _root.onMouseDown = obj.mouseDown;
The problem is that you cannot access any other member of the obj Object, for example the something variable. Anyone know how to fix this?Code:[object Object] _level0 undefined _level0 undefined _level0 undefined _level0 undefined




Reply With Quote