Thursday 11 March 2010

Actionscript 3: Error: Call to possibly undefined method addEventListener through a reference with a static type class

If you have been following Gustavo Kawamoto's instructions for making a Actionscript 3 static, singleton class you might be have received the undefined method addEventListener error when trying to set up an event listener for your static object.

The thing to remember is that you must add an event listener on an object instance, so try the following:

MyStaticClass.getInstance().addEventListener(MyEvent.BLAH, myHandler);


This works since the getInstance() method returns the instance of your static singleton.