[Solved] joint on creation

Hey, so i want to make a waterfall in flash. I made an enter-frame event that adds circles over and over, but i want them to stick together. Is there a way I can make them join with any nearby circle if it is within a certain distance? Here's what i did.
http://flashpotatoes.deviantart.com/art ... -110475075
Well, you can try to stick them together when they hit each other 🙂

Yeah, this might help :
viewtopic.php?f=3&t=574
so i tried it out, but i'm relatively new to box2d, and i failed haha. here's my code
Code:
for (var dd:b2ContactEdge = bb.m_contactList; dd; dd = dd.next) {
   if (dd.other.m_userData is Water&&bb.m_userData is Water){
      var ddPoint:b2Vec2 = new b2Vec2(dd.GetPosition().x * m_physScale, dd.GetPosition().y * m_physScale);
      var bbPoint:b2Vec2 = new b2Vec2(bb.GetPosition().x * m_physScale, bb.GetPosition().y * m_physScale);
                     
      joint = new b2DistanceJointDef();
      joint.Initialize(dd, bb, ddPoint, bbPoint);
      joint.collideConnected = false;
   }
}

This is all in my Update enter_frame event.
Hope you can help 😀
You need to call the world's CreateJoint(joint) method to actually create the joint.
(assuming that the ActionScript port works similarly to the C++ version)
so i made some changes. thanks for your comments by the way 😀 i have one problem left. i think instead of making joints in between each other, they are joining with themselves because none of them are joining together, and the game slowed down a bunch. here's the new code.
Code:
for (var dd:b2Body = m_world.m_bodyList; dd; dd = dd.m_next) {
   if (dd.m_userData is Water&&bb.m_userData is Water){
      var ddPoint:b2Vec2 = new b2Vec2(dd.GetPosition().x * m_physScale, dd.GetPosition().y * m_physScale);
      var bbPoint:b2Vec2 = new b2Vec2(bb.GetPosition().x * m_physScale, bb.GetPosition().y * m_physScale);
                     
      joint = new b2DistanceJointDef();
      joint.Initialize(dd, bb, ddPoint, bbPoint);
   }
}

it at least runs, but it's basically pointless unless the joints are made with each other. bb by the way is "var bb:b2Body = m_world.m_bodyList". so basically the same as dd, except the For loop for dd is inside the For loop where bb is made. I want to have each object made be bb, and each object bb touches be dd. I hope that makes sense 🙂
Yeah, you must add it to the world!
You must check if there is a joint already as well.
Yeah i'm new to joints. I hadn't gotten to that part in the manual. So anyway, I created the joint.
Code:
for (var dd:b2ContactEdge = bb.m_contactList; dd; dd = dd.next) {
   if (dd.other.m_userData is Water&&bb.m_userData is Water){
                     
      var ddPoint:b2Vec2 = new b2Vec2(dd.GetPosition().x * m_physScale, dd.GetPosition().y * m_physScale);
      var bbPoint:b2Vec2 = new b2Vec2(bb.GetPosition().x * m_physScale, bb.GetPosition().y * m_physScale);
                     
      joint = new b2DistanceJointDef();
      joint.Initialize(dd, bb, ddPoint, bbPoint);
      m_world.CreateJoint(joint);
      break;
   }
}

So I can't create the joint because dd is just a b2ContactEdge to check if it hits bb, which is a body. So if I wanted to create a body out of dd like say "var ddb:b2Body = dd.so and so", how do I do that?
Hey I solved it. I just had to do dd.other.GetPosition and it worked. dd was the Contact Edge. Thanks 🙂

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