How to run a function from b2ContactListener ?

I set up the b2ContactListener by writing :
Code:
var m_contactListener=new b2ContactListener();
m_world.SetContactListener(m_contactListener);

In the Document Class.

How do you run a function that is on the Document Class from b2ContactListener ?

if i write:
Code:
public virtual function Add(point:b2ContactPoint) : void{
     function1();
}


doesnt work, even if i set up public function in the document class.
I am sure its a dumb question, but i am kinda confused, how can i do it? 😕
You have to extend b2ContactListener with your own contact listener class
Code:
class MyContactListener extends b2ContactListener

Then implement Add, Remove or Persist (as needed), and they will automatically be called.
Code:
class ContactListener extends b2ContactListener{
  override public function Add(point:b2ContactPoint):void{
    //DO SOME STUFF
  }
}


But, if you are going to do physics related stuff in your Add function, it's better not to do those directly from the contact listener callback, because you will be modifying the physics world inside a timestep. That's generally a very very bad idea. So, take a look at http://www.box2d.org/wiki/index.php?tit ... _Box2D_AS3 to find out how you can buffer your contacts, and process them after the timestep.

Original thread: https://box2d.org/forum/viewtopic.php?t=3041