This is roughly what's happening....
All the objects listen for an event.
If the if_statement is true, fire the event.
Any object's listening for the event react.
Since all the objects are listening for the event, they all react.
....what else do you expect?!
Ahh...ok I see why you're getting confused. I've had a closer look at the tutorial.
I've been following Allan's tutorials too and mostly they're really good, but personally I think he's taken an overcomplicated and rather stupid approach on this one...I suspect that if you have more than one red ball, then if any red ball hit's the ground - all red balls will react. Likewise with blue balls.
Personally I see absolutely no reason to use event dispatcher unless you want several objects to react to one event, or you can't get a reference to the object from the b2Contact.
You need to do something like this...
Code:
override public function BeginContact(contact:b2Contact):void
{
if (contact.GetFixtureA().GetBody().GetUserData().type == doc_class.BRUSSEL_SPROUT && contact.GetFixtureB().GetBody().GetUserData().type == doc_class.PLATE_SENSOR)
{
contact.GetFixtureA().GetBody().nameOfFunctionToRun(); // Brussel_sprout reaction
contact.GetFixtureB().GetBody().nameOfFunctionToRun(); // Plate sensor reaction
}
if (contact.GetFixtureA().GetBody().GetUserData().type == doc_class.PLATE_SENSOR && contact.GetFixtureB().GetBody().GetUserData().type == doc_class.BRUSSEL_SPROUT)
{
contact.GetFixtureA().GetBody().nameOfFunctionToRun(); // Plate sensor reaction
contact.GetFixtureB().GetBody().nameOfFunctionToRun(); // Brussel_sprout reaction
}
}
....since nobody seems to want to answer my question on this forum, also about the contact listener, I'm going to have a go at this tonight and see if I can get it working properly. I'll probably learn a lot. Watch this space!