Help! ContactEvent and Joint!

Hello Everyone!
I need help with creating a joint when ContactEvent is triggered. I keep on getting an error which I so far only understand that it has got something to do with creating the joint. This class is in a Sensor, so what I want to do is to make the sensor contact a box and only create one joint for the sensor and box. This sensor is attached to a BoxMan.

Thank you In advance! XD

Code:
public override function create():void {
         reportBeginContact = true;
         reportEndContact = true;
         fixedRotation = true;
         super.create();
         addEventListener(ContactEvent.BEGIN_CONTACT, handleContact);
         contacts = new ContactList();
         contacts.listenTo(this);
      }
      
      public function handleContact(e:ContactEvent):void {
         var b:BodyShape = Util.findAncestorOfClass(e.target as DisplayObject, BodyShape, true) as BodyShape;
         trace(e.target); //traces: Sensor not Box
         if(b) {
            createHeroJoint(b);
         }
      }
     
     public function createHeroJoint(B:BodyShape):void {
       var j:joint = new joint();
       trace("!");
       j.x = this.body.x; j.y = this.body.y;
       j.bodyShape1 = this.body;
       j.bodyShape2 = b.body;
       j.type = 'Revolute';
       world.addChild(j);
      }
If you post the exact text of the error message this would be easier to debug. Anyway I'm thinking the problem is that you're creating a joint while inside the time step.

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