Error on Destroying Jointed Object

Hello Guys,

I'm new with wck and I'm desperately need your help with this topic.

Image

So based on the image above. I have a movieclip called projectile_mc that I want to collide with the bar_mc with a joint attached to it. Then once they collided I would like to remove/destroy bar_mc. But I'm encountering an error on my output panel.

Code:
TypeError: Error #1006: value is not a function.
   at cmodule.Box2D::FSM__ZN7b2World12DestroyJointEP7b2Joint/work()
   at <anonymous>()
   at <anonymous>()
   at Box2DAS.Dynamics.Joints::b2Joint/destroy()
   at <anonymous>()
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at wck::World/step()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at <anonymous>()
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at wck::World/step()


This happens everytime I have a joint attached to the bar_mc. But if there's no joint attached to it. It works perfectly.

This is my code inside bar_mc

Code:
import Box2DAS.*;
import Box2DAS.Collision.*;
import Box2DAS.Collision.Shapes.*;
import Box2DAS.Common.*;
import Box2DAS.Dynamics.*;
import Box2DAS.Dynamics.Contacts.*;
import Box2DAS.Dynamics.Joints.*;
import cmodule.Box2D.*;
import wck.*;
import shapes.*;
import misc.*;
import extras.*;
import flash.utils.*;
import flash.events.*;
import flash.display.*;
import flash.text.*;
import flash.geom.*;

var contacts:ContactList;

this.reportBeginContact=true;
this.reportEndContact=true;
contacts = new ContactList();
contacts.listenTo(this);

listenWhileVisible(this, ContactEvent.END_CONTACT, handleContact1);

function handleContact1(e:ContactEvent):void {
   

   var q:mc_projectile=e.other.m_userData as mc_projectile;
   if (q) {
      this.remove();
   }

}



I would like to know if jointed object(s) can be removed/destroyed?

Any assistance is greatly appreciated.

Thanks!
Haha, same error I'm getting. viewtopic.php?f=19&t=6969
yeah... i think our problem got some resemblances... huhuhu... mayo I need your magic... please help me
Try this:

Code:
world.doOutsideTimeStep(function():void {
    this.remove();
}


WCK should wait until outside of the timestep to destroy the body, but with a joint involved the order things are destroyed might get messed up.

If that doesn't fix it there's something else going on.
mayobutter wrote:
Try this:

Code:
world.doOutsideTimeStep(function():void {
    this.remove();
}


WCK should wait until outside of the timestep to destroy the body, but with a joint involved the order things are destroyed might get messed up.

If that doesn't fix it there's something else going on.



Thanks for the response man! =)

I tried placing the code inside bar_mc but it gives me an error.

Maybe there's a typo or something


by the way, I placed the code inside handleCOntact1 function

Code:
listenWhileVisible(this, ContactEvent.END_CONTACT, handleContact1);

function handleContact1(e:ContactEvent):void {
   

   var q:mc_projectile=e.other.m_userData as mc_projectile;
   if (q) {
      world.doOutsideTimeStep(function():void {
    this.remove()
});
   }

}



am i doing it the right way?
Well what's the error?
mayobutter wrote:
Well what's the error?



I'm encountering this error 🙁

Code:
TypeError: Error #1006: remove is not a function.
   at <anonymous>()
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at wck::World/step()
TypeError: Error #1006: remove is not a function.
   at <anonymous>()
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at wck::World/step()
Ok try this. I'm just coding from memory. I think "this" doesn't work because you're in a function.

Code:
var t:* = this;
world.doOutsideTimeStep(function():void {
    t.remove();
});


Or wait, just this.

Code:
world.doOutsideTimeStep(remove);


Basically you want to remove it outside of the timestep, however you want to handle that.
mayobutter wrote:
Ok try this. I'm just coding from memory. I think "this" doesn't work because you're in a function.

Code:
var t:* = this;
world.doOutsideTimeStep(function():void {
    t.remove();
});


Or wait, just this.

Code:
world.doOutsideTimeStep(remove);


Basically you want to remove it outside of the timestep, however you want to handle that.




Holy cow!!! you're second example works! Thanks very much!!! I really appreciate your help.... you're the man!
deliciouso wrote:
mayobutter wrote:
Ok try this. I'm just coding from memory. I think "this" doesn't work because you're in a function.

Code:
var t:* = this;
world.doOutsideTimeStep(function():void {
    t.remove();
});


Or wait, just this.

Code:
world.doOutsideTimeStep(remove);


Basically you want to remove it outside of the timestep, however you want to handle that.




Holy cow!!! you're second example works! Thanks very much!!! I really appreciate your help.... you're the man!


Oh my gosh, doing this when I get home.

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