A problem with learning distance joints

Discuss issues specific to the Flash/AS3 port of Box2D
rimacy
Posts: 2
Joined: Mon Feb 18, 2013 12:12 pm

A problem with learning distance joints

Postby rimacy » Mon Feb 18, 2013 12:21 pm

Hi guys, I'm working through Emmanuel Ferranto's book Box2DForFlashGames and I'm stumped on something that seems like it should not be a problem.

Im making a distance joint between two blocks that can be dragged by the mouse.

Here's the code:

Code: Select all

var groundBody:b2Body = world.CreateBody(bodyDef);
         groundBody.CreateFixture(fixtureDef);
         
         bodyDef.position.Set(320 / worldScale, 430 / worldScale);
         bodyDef.type = b2Body.b2_dynamicBody;
         polygonShape.SetAsBox(30 / worldScale, 30 / worldScale);
         fixtureDef.density = 1;
         fixtureDef.friction = .4;
         fixtureDef.restitution = .2;
         
         var box2:b2Body = world.CreateBody(bodyDef);
         box2.CreateFixture(fixtureDef);
         
         bodyDef.position.Set(420 / worldScale, 430 / worldScale);
         var box3:b2Body = world.CreateBody(bodyDef);
         box3.CreateFixture(fixtureDef);
         
         var dJointDef:b2DistanceJointDef = new b2DistanceJointDef();
         
         dJointDef.bodyA = box2;
         dJointDef.bodyA = box3;
         
         dJointDef.localAnchorA = new b2Vec2(0, 0);
         dJointDef.localAnchorB = new b2Vec2(0, 0);
         dJointDef.length = 100 / worldScale;
         
         
         
         var distanceJoint:b2DistanceJoint;
         distanceJoint = world.CreateJoint(dJointDef ) as b2DistanceJoint;
   


Here's my error:
[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.


the error is thrown for this line:

Code: Select all

distanceJoint = world.CreateJoint(dJointDef ) as b2DistanceJoint;
      

If I comment out this line everything goes right along.

The locals panel shows bodyA as undefined, bodyB as undefined and edge as null. I don't know if these are important or not but its the only thing I could find.

Any body have any clues?????

rimacy
Posts: 2
Joined: Mon Feb 18, 2013 12:12 pm

problem with learning distance joints SOLVED

Postby rimacy » Mon Feb 18, 2013 6:39 pm

Sorry everybody. Just a typeO that i've been staring at for three days.

Code: Select all

dJointDef.bodyA = box2;
         dJointDef.bodyA = box3;


Im just reassigning box3 to dJointDef.bodyA instead of bodyB so bodyB was null!!! >>blush<<


Return to “Flash”



Who is online

Users browsing this forum: No registered users and 2 guests