flash cs3 box2d component

hello!
I'm trying to create a set of box2d component for flash cs3. but now i'm in trouble... basically i create a single shape component for every type, but now i want to aggregate the box, circle and poly.
I was able to make working box and circle, but i've problem with triangle... Maybe because i'm not a programmer. 😳

here the code of the body component:
there is somebody so kindle to explane me what it's wrong?

Code:
package FrameworkObject{

   import fl.core.UIComponent;
   import FrameworkObject.DynamicMovieComponent;
   import FrameworkObject.ObjPerimeter;
   import FrameworkObject.TraceUtil;
   import flash.display.Shape;
   import flash.display.Sprite;
   import flash.display.MovieClip;
   import flash.geom.Rectangle;
   import flash.geom.Point;
   import Box2D.Dynamics.*;
   import Box2D.Collision.*;
   import Box2D.Collision.Shapes.*;
   import Box2D.Common.Math.*;
   
   public class PhysBox extends DynamicMovieComponent{
      
      private var bodyDef:b2BodyDef;
      private var shapeDef:*;//can be b2sBoxDef, b2CircleDef, b2PolyDef;
      
      protected var _world:b2World;
      protected var _body:b2Body;
      protected var _bodyType:String = "CIRCLE";
      protected var _skinName:String = "BODY_SKIN";
      protected var _density:Number = 0;
      protected var _friction:Number = 0.2;
      protected var _restitution:Number = 0;
      protected var _linearVelocity:Object = {x:0,y:0};
      protected var _angularVelocity:Number = 0;
      protected var _linearDamping:Number = 0;
      protected var _angularDamping:Number = 0;
      protected var _allowSleep:Boolean = true;
      protected var _isSleeping:Boolean = false;
   //   protected var _isBullet:Boolean = false;
      
      
      private var skin:MovieClip;
      
      public function PhysBox()
      {
         super();
         // Add ground body
         bodyDef = new b2BodyDef();
      };
      
      protected override function draw():void
      {
         
         super.draw();
         
         if(isLivePreview)
         {
            (skinName != "BODY_SKIN")?addSkin(bodyType+"_USER"):addSkin(bodyType);
         }
         else
         {
            addSkin(skinName)
         }
         if(bodyType == "CIRCLE")
         {   
            skin.y = (height-width)/2;
            skin.height = width;
         }
         else
         {
            skin.height = height;
         }
         skin.width = width;
         
         if(!isLivePreview && world!=null)initPhysBody();
      }
      
      public function get world():b2World
      {
         return _world;
      }
      public function set world(world_:b2World):void
      {
         if(world_ == _world){ return; }
         _world = world_;
      }
      
      public function get body():b2Body
      {
         return _body;
      }
      public function set body(body_:b2Body):void
      {
         if(body_ == _body){ return; }
         _body = body_;
      }
      
      [Inspectable(type="List", enumeration="CIRCLE,BOX,TRIANGLE,AUTOPOLYGON", defaultValue="CIRCLE", name="bodyType")]
      public function get bodyType():String
      {
         return _bodyType;
      }
      public function set bodyType(bodyType_:String):void
      {
         if(bodyType_ == _bodyType){ return; }
         _bodyType = bodyType_;
      }
      
      [Inspectable(defaultValue="0",type="Number", name="density")]
      public function get density():Number
      {
         return _density;
      }
      public function set density(density_:Number):void
      {
         _density = density_;
         if(shapeDef == undefined || shapeDef.density == density_){ return; }
         shapeDef.density = density_;
      }
      
      [Inspectable(defaultValue="0.2",type="Number", name="friction")]
      public function get friction():Number
      {
         return _friction;
      }
      public function set friction(friction_:Number):void
      {
         _friction = friction_;
         if(shapeDef == undefined || shapeDef.friction == friction_){ return; }
         shapeDef.friction = friction_;
      }
      
      [Inspectable(defaultValue="0",type="Number", name="restitution")]
      public function get restitution():Number
      {
         return _restitution;
      }
      public function set restitution(restitution_:Number):void
      {
         _restitution = restitution_;
         if(shapeDef == undefined || shapeDef.restitution == restitution_){ return; }
         shapeDef.restitution = restitution_;
      }
      
      [Inspectable(defaultValue="x:0,y:0",type="Object", name="linearVelocity")]
      public function get linearVelocity():Object
      {
         return _linearVelocity;
      }
      public function set linearVelocity(linearVelocity_:Object):void
      {
         if(bodyDef.linearVelocity == new b2Vec2(linearVelocity_.x, linearVelocity_.y)){ return; }
         bodyDef.linearVelocity = new b2Vec2(linearVelocity_.x, linearVelocity_.y);
         _linearVelocity = linearVelocity_;
      }
      
      [Inspectable(defaultValue="0",type="Number", name="angularVelocity")]
      public function get angularVelocity():Number
      {
         return _angularVelocity;
      }
      public function set angularVelocity(angularVelocity_:Number):void
      {
         if(bodyDef.angularVelocity == angularVelocity_){ return; }
         bodyDef.angularVelocity = angularVelocity_;
         _angularVelocity = angularVelocity_;
      }
      
      [Inspectable(defaultValue="0",type="Number", name="linearDamping")]
      public function get linearDamping():Number
      {
         return _linearDamping;
      }
      public function set linearDamping(linearDamping_:Number):void
      {
         if(bodyDef.linearDamping == linearDamping_){ return; }
         bodyDef.linearDamping = linearDamping_;
         _linearDamping = linearDamping_;
      }
      
      [Inspectable(defaultValue="0",type="Number", name="angularDamping")]
      public function get angularDamping():Number
      {
         return _angularDamping;
      }
      public function set angularDamping(angularDamping_:Number):void
      {
         if(bodyDef.angularDamping == angularDamping_){ return; }
         bodyDef.angularDamping = angularDamping_;
         _angularDamping = angularDamping_;
      }
      
      
      [Inspectable(defaultValue="true",type="Boolean", name="allowSleep")]
      public function get allowSleep():Boolean
      {
         return _allowSleep;
      }
      public function set allowSleep(allowSleep_:Boolean):void
      {
         if(bodyDef.allowSleep == allowSleep_){ return; }
         bodyDef.allowSleep = allowSleep_;
         _allowSleep = allowSleep_;
      }
      
      [Inspectable(defaultValue="false",type="Boolean", name="isSleeping")]
      public function get isSleeping():Boolean
      {
         return _isSleeping;
      }
      public function set isSleeping(isSleeping_:Boolean):void
      {
         if(bodyDef.isSleeping == isSleeping_){ return; }
         bodyDef.isSleeping = isSleeping_;
         _isSleeping = isSleeping_;
      }
      /*
      [Inspectable(defaultValue="false",type="Boolean", name="isBullet")]
      public function get isBullet():Boolean
      {
         return _isBullet;
      }
      public function set isBullet(isBullet_:Boolean):void
      {
         if(isBullet_ == _isBullet){ return; }
         shapeDef.isBullet = isBullet_;
         _isBullet = isBullet_;
      }*/
      
      [Inspectable(defaultValue="BODY_SKIN", type=String, name="skinName")]
      public function get skinName():String
      {
         return _skinName;
      }
      
      public function set skinName(skinName_:String):void
      {
         if(skinName_ == _skinName){ return; }
         
         _skinName = skinName_;
      }
      
      public function initPhysBody():void
      {
         switch(bodyType)
         {
         case "CIRCLE":
            setRegistration(width/2, height/2);//corresponding on the baricenter (center of mass);
            shapeDef = new b2CircleDef();
            shapeDef.radius = width/2;
            break
         case "BOX":
            setRegistration(width/2, height/2);
            shapeDef = new b2BoxDef();
            shapeDef.extents.Set(width/2, height/2);
            break
         case "TRIANGLE":
            setRegistration(width/2,(height*2)/3);
            shapeDef = new b2PolyDef();
            shapeDef.vertexCount = 3;
            shapeDef.vertices[0].Set(width,height);
            shapeDef.vertices[1].Set(width/2,0);
            shapeDef.vertices[2].Set(0,height);
            
            break
         case "AUTOPOLYGON":
            shapeDef = new b2PolyDef();
            //shapeDef.type = b2Shape.e_polyShape
            //shapeDef.vertexCount = b2Settings.b2_maxPolyVertices;
            //var vertices:Array = ObjPerimeter.simplifyArray(ObjPerimeter.arrayPerimeter(this,200,2),shapeDef.vertexCount);
            shapeDef.vertexCount = 7;
            var vertices:Array = ObjPerimeter.simplifyArray(ObjPerimeter.arrayPerimeter(this,200,2),7);
            for(var j = 0; j < 7; j++)
            {
               shapeDef.vertices[j].Set(vertices[j].x,vertices[j].y);
            }
            //bodyDef.position.Set(shapeDef.vertices[0].x,shapeDef.vertices[0].y);
            break
         }
         addShapeParam();
         bodyDef.position.Set(x2,y2);
         bodyDef.rotation = rotation / (180/Math.PI);
         bodyDef.AddShape(shapeDef);
         bodyDef.userData = this;
         body = world.CreateBody(bodyDef);
      }
      
      public function update():void
      {
         x2 = body.m_position.x;
         y2 = body.m_position.y;
         rotation2 = body.m_rotation * (180/Math.PI);
         
         
         if(bodyType == "TRIANGLE")
         {
            var drw:Array = new Array(shapeDef.vertices[0],shapeDef.vertices[1],shapeDef.vertices[2]);
            TraceUtil.traceArrayPoint(parent,drw,0xff0000)
         }
      };
      
      private function addShapeParam():void
      {
         density = density;
         friction = friction;
         restitution = restitution;
      };
      
      private function addSkin(skinName:String):void
      {
         var classDef;
         
         if(numChildren > 0)
         {
            if(skin.name == skinName)
               return
            
            skin = null;
            removeChildAt(0);
         }
         
         try
         {
            classDef=this.loaderInfo.applicationDomain.getDefinition(skinName);
         }
         catch (e:ReferenceError)
         {
            try
            {
               classDef=this.loaderInfo.applicationDomain.getDefinition(bodyType);
            }
            catch (e:ReferenceError)
            {
               return;
            }
         }
         skin = new classDef as MovieClip;
         addChild(skin);
      };
   }
}



maybe it's difficult understand 300 line of inuseful code, but i think that the problem is located in the function initPhysBody

in the switch case TRIANGLE.

and so in the update method.

I don't understad why the box and circle work and the triangle s'not...

confused 😕 😕
I always get confused on this, but I think your triangle vertices are the wrong way round. Try flipping the order, and seeing if it works then.
i'm wondering about this... 😮
the vertex order is important? what's the logic???

Anyway i've improved the code, i hope tomorrow the component will work properly!!!
You can read about polygon authoring in the manual:

http://www.box2d.org/manual.html#d0e900

Box2D uses the vertex order to compute the outward normal vector for each edge.
thhhhhhhhhaaaaaankkkks!!!!!

Now it's "As clear as an azure sky of deepest summe"...

i'm afraid, i did'n found that dodcumentation!
reading the documentation i've finally done de PhisicBody component that map all the functionality of the b2Body;
now i'm in trouble with the RevoluteJoint component...

1 i've make an instance of the b2RevoluteJointDef
jd = new b2RevoluteJointDef();
2 i set some parameter
jd.anchorPoint.Set(x2, y2);
jd.body1 = retriveBody(body1);
jd.body2 = retriveBody(body2);

jd.lowerAngle = GeomUtil.gradToRad(lowerAngle);
jd.upperAngle = GeomUtil.gradToRad(upperAngle);
jd.userData = this;
3 i add the joint in the world
joint = world.CreateJoint(jd);

now my problem is:

i want to add the b2RevoluteJoint propertyes (maxMotorTorque etc...)
but joint isn't a b2RevoluteJoint, it's a b2Joint.

I declare joint as a b2RevoluteJoint but
I can't do the world.CreateJoint(jd) function.

So there is something that i don't understand.

somebody can help me????? 😕
ok... i'm working on it.
and i've just finished the revolutive joint component.
I'd like to put something in the repository... but... there is an as3 repository???
maybe i'm misunderstanding you, but why wouldn't you just add those properties to 'jd' rather than 'joint'? jd is your b2RevoluteJointDef so thats where the properties should be applied.

for example:
Code:
jd.enableMotor = true;
jd.motorSpeed = -7;
jd.motorTorque = 10000000
hi Beeryan!

It was my mistake.I tried using maxMotorTorque instead of motorTorque.

Now my problem is: why i set these parameter

jd.enableMotor = true;
jd.motorSpeed = -7;
jd.motorTorque = 10000000

and doesn't uppend nothing???

maybe (I'm not a physic, I'm a stage designer). I'm not understood the meaning about the Motor parameter.

any help will be apreciated
OK, reading the documentation i understood that motor it's "setup to simulate joint friction".

so less velocity means less joint friction?
torque it's like te power of the joint?

attached a small example

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