Box2D Forums

It is currently Sun May 19, 2013 1:59 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed May 18, 2011 3:49 pm 
Offline

Joined: Wed May 18, 2011 12:42 pm
Posts: 5
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!


Top
 Profile  
 
PostPosted: Wed May 18, 2011 6:54 pm 
Offline

Joined: Mon Jul 12, 2010 2:15 am
Posts: 47
Haha, same error I'm getting. viewtopic.php?f=19&t=6969


Top
 Profile  
 
PostPosted: Thu May 19, 2011 1:05 pm 
Offline

Joined: Wed May 18, 2011 12:42 pm
Posts: 5
yeah... i think our problem got some resemblances... huhuhu... mayo I need your magic... please help me


Top
 Profile  
 
PostPosted: Thu May 19, 2011 1:13 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
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.


Top
 Profile  
 
PostPosted: Thu May 19, 2011 1:30 pm 
Offline

Joined: Wed May 18, 2011 12:42 pm
Posts: 5
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?


Top
 Profile  
 
PostPosted: Thu May 19, 2011 2:00 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
Well what's the error?


Top
 Profile  
 
PostPosted: Thu May 19, 2011 2:04 pm 
Offline

Joined: Wed May 18, 2011 12:42 pm
Posts: 5
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()


Top
 Profile  
 
PostPosted: Thu May 19, 2011 2:45 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
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.


Top
 Profile  
 
PostPosted: Thu May 19, 2011 2:50 pm 
Offline

Joined: Wed May 18, 2011 12:42 pm
Posts: 5
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!


Top
 Profile  
 
PostPosted: Fri May 20, 2011 10:29 am 
Offline

Joined: Mon Jul 12, 2010 2:15 am
Posts: 47
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group