Shape creation

Whenever I do this in box2d:
Code:
  // Either circle or polygon.
         var shapeOfBox:b2PolygonShape = new b2PolygonShape;
         
         // Amount of vertices.
         var amountOfVertices:int = 4;
         
         // Create a new array so we can put our coordinates of each
         // point of a vertices.
         var verticesOfBox:Array = new Array();
         
         // The vertices go clockwise so I am going to
         // start with the one in the top left.
         verticesOfBox[0].Set(0, 0);
         
         // Top right vertice of box.
         verticesOfBox[1].Set(100, 0);
         
         // Bottom right vertice.
         verticesOfBox[2].Set(100, 100);
         
         // Bottom left vertice.
         verticesOfBox[3].Set(0, 100);
         
         // Assign the vertices of our box to our
         // shape as well as the amount of points there
         // are.
         shapeOfBox.SetAsArray(verticesOfBox, amountOfVertices);
         


Nothing appears in debug when I do that.

However if I do this:

Code:
shapeOfBox.SetAsBox(100, 100);


it works fine and I see a square in debug draw.



Why doesn't the first method work? I need it to work in case I want to make a pentagon or a trapezoid or a triangle.
each coordinate in the vertices array has to be b2Vec2.

Code:
         var shapeOfBox:b2PolygonShape = new b2PolygonShape;
         var amountOfVertices:int = 4;
         var verticesOfBox:Array = new Array();

        for (var i:int = 0; i< amountOfVertices; i++)
        {
                 verticesOfBox[0]= new b2Vec2();
        }
         verticesOfBox[0].Set(0, 0);
         verticesOfBox[1].Set(100, 0);
         verticesOfBox[2].Set(100, 100);
         verticesOfBox[3].Set(0, 100);
     
      shapeOfBox.SetAsArray(verticesOfBox, amountOfVertices);
I got...
Code:
Assertion Failed
   at Box2D.Common::b2Settings$/b2Assert()
   at Box2D.Collision.Shapes::b2PolygonShape/SetAsVector()
   at Box2D.Collision.Shapes::b2PolygonShape/SetAsArray()


this is what I put...
Code:
var shape:b2PolygonShape = new b2PolygonShape();
         var shapeVert:Array = new Array();
         shapeVert[0] = new b2Vec2();
         shapeVert[1] = new b2Vec2();
         shapeVert[2] = new b2Vec2();
         shapeVert[3] = new b2Vec2();
         shapeVert[0].Set(0, 0);
         shapeVert[1].Set(widthOfBox, 0);
         shapeVert[2].Set(widthOfBox, 0);
         shapeVert[3].Set(0, heightOfBox);
         shape.SetAsArray(shapeVert, 4);
         //shape.SetAsBox(widthOfBox, heightOfBox);




EDIT: For some reason you can't start of with a 0,0 point.
Works now = )

Code:
var shape:b2PolygonShape = new b2PolygonShape();
         var shapeVert:Array = new Array();
         shapeVert[0] = new b2Vec2(0, heightOfBox);
         shapeVert[1] = new b2Vec2(0, 0);
         shapeVert[2] = new b2Vec2(widthOfBox, 0);
         shapeVert[3] = new b2Vec2(widthOfBox, heightOfBox);
         
         shape.SetAsArray(shapeVert, 4);

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