On contact remove other object

Hi all,

I've got a (i think) simple question.

I want to remove object B when I contact object A. I'm wondering how I can interact with the other object.

BoxMan class:
Code:
var objectA:ObjectA= e.other.m_userData as ObjectA;
var objectB:ObjectB= ??????? as ObjectB;

if (objectA) {
   objectB.remove();
}   
See this property of Box2D.Dynamics.ContactEvent:

Code:
      /// the "target" property is the fixture userData dispatching the event, the "relatedObject" is the userData
      /// of the other fixture involved in the contact.
      public var relatedObject:*;


So maybe you want your code to look like this?

Code:
var objectA:ObjectA= e.relatedObject as ObjectA;
var objectB:ObjectB= e.target as ObjectB;

if (objectA) {
   objectB.remove();
}   



"target" is the BodyShape from which the contact event originated.
"relatedObject" is the other BodyShape involved in the collision.
Hi mayobutter, thanks for your time.

Maybe it's not very clear, this is what I want to do:

If (Player contacts BoxA){
remove BoxB
}

so target is my Player
relatedObject is BoxA
... but how to get interaction with BoxB?
Oh, well is your object placed on the stage in Flash or is it dynamically created in code? If it's placed on the stage you can give it an instance name and do:

Util.remove(world.getChildByName('instance_name_of_object'));

If it's in code, you'll have to store the object in a variable somewhere and essentially do the same thing.
Thanks mayobutter that did the trick.

Now I can go on with my project !
Hey, i'm trying to do the exact same thing as toinev, but also add a new symbol/movieclip at the position of objectB before it is removed (so instead of objectB just instantly disappearing, i can add a movieclip there that shows it fading out or something).

So i guess it would be something like:
Code:
var objectA:objectA = e.other.m_userData as objectA;
if(objectA) {
   Util.addChildAtPosOf(world, new SymbolAtObjectAPostition(), objectA);
   objectA.remove();

   code here to add symbol at objectB position

   Util.remove(world.getChildByName('objectB'));
}

Not sure what to do?
So you mean something like this?


Code:
Util.addChildAtPosOf(world, new SymbolAtObjectBPostition(), world.getChildByName('objectB'))
Thats exactly it mayo! Cheers once again 🙂

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