The errors are to do with the Box2D engine being updated. The excellent tutorials by FlashyTodd are unfortunately out of date now (22/10/10). Although he does mention this at the top of the videos the link to the things that have changed isn't much use for the novice (myself included).
Also the link above to the Box2D manual from DrDeth is the C++ manual, not AS3 which is what FlashyTodd is working through.
I also found this useful example which notes the changes made from 2.0 to 2.1 code.
For anyone else that comes across this, here is the FlashyTodd example HelloBoxWorld updated to be Box2D 2.1 compliant. (just a floor and dynamic box)
package{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import Box2D.Dynamics.b2World;
import Box2D.Collision.Shapes.b2PolygonShape;
import Box2D.Dynamics.b2Body;
import Box2D.Dynamics.b2Fixture;
import Box2D.Dynamics.b2FixtureDef;
import Box2D.Dynamics.b2BodyDef;
import Box2D.Common.Math.b2Vec2;
import Box2D.Collision.b2AABB;
import Box2D.Dynamics.b2DebugDraw;
public class HelloBoxWorld extends MovieClip{
protected var _world:b2World;
//ratio of pixels to meters.
public static const RATIO:Number = 30;
private var _fallingCrate:b2Body;
private var timeStep:Number = 1.0 / 30.0;
private var velocityIterations:int = 6;
private var positionIterations:int = 2;
public function HelloBoxWorld() {
//1. set up the world
setupWorld();
//2. create walls and floor
createWallsAndFloor();
//3. make create
addACrate();
setupDebugDraw();
addEventListener(Event.ENTER_FRAME, newFrameEvent);
}
private function setupDebugDraw():void {
var spriteToDrawOn:Sprite = new Sprite();
addChild(spriteToDrawOn);
var artistForHire:b2DebugDraw = new b2DebugDraw();
artistForHire.SetSprite(spriteToDrawOn);
artistForHire.SetDrawScale(RATIO);
artistForHire.SetFlags(b2DebugDraw.e_shapeBit);
artistForHire.SetLineThickness(2.0);
artistForHire.SetFillAlpha(0.6);
_world.SetDebugDraw(artistForHire);
}
private function newFrameEvent(e:Event):void {
//variables assigned at the top
_world.Step(timeStep, velocityIterations, positionIterations);
_world.ClearForces();
_world.DrawDebugData();
trace("Falling Craete is at x:"+_fallingCrate.GetPosition().x +",y:"+_fallingCrate.GetPosition().y);
}
private function setupWorld():void {
//1. set up the size of the universe
//var universeSize:b2AABB = new b2AABB();
//universeSize.lowerBound.Set (-3000/RATIO,-3000/RATIO);
//universeSize.upperBound.Set (3000/RATIO,3000/RATIO);
//2. Define gravity
var gravity:b2Vec2 = new b2Vec2(0, 9.8);
//3. Ignore sleeping objects.
var ignoreSleeping:Boolean = true;
_world = new b2World(gravity, ignoreSleeping);
trace ("My world has "+_world.GetBodyCount()+" bodies");
}
private function createWallsAndFloor():void {
//1. Define a body with a position
var groundBodyDef:b2BodyDef = new b2BodyDef();
//x,y of centre. set as integers, not floats
groundBodyDef.position.Set(250 / RATIO, 400 / RATIO);
//2. Use the world object to create the body using the body definition above
var groundBody = _world.CreateBody(groundBodyDef);
//3. Define fixtures with a shape, friction, density, etc.
var groundBox:b2PolygonShape = new b2PolygonShape();
//width ,height. set as integers, not floats
groundBox.SetAsBox(200 / RATIO, 20 / RATIO);
var fixtureDef:b2FixtureDef = new b2FixtureDef();
fixtureDef.shape = groundBox;
fixtureDef.density = 0.0;//density is set to 0.0 by default so this isnt really needed here
fixtureDef.friction = 0.5;
groundBody.CreateFixture(fixtureDef);
trace ("My world has "+_world.GetBodyCount()+" bodies");
}
private function addACrate():void {
//moving object
var movingBodyDef:b2BodyDef = new b2BodyDef();
//set the type of body here
movingBodyDef.type = b2Body.b2_dynamicBody;//b2_dynamicBody is a property of b2Body. !manual is confusing here.
movingBodyDef.position.Set(100.0 / RATIO, 100.0 / RATIO);
movingBodyDef.angle = 30 * Math.PI / 180;
_fallingCrate = _world.CreateBody(movingBodyDef);
var dynamicBox:b2PolygonShape = new b2PolygonShape();
dynamicBox.SetAsBox(50.0 / RATIO, 50.0 / RATIO);
var dynamicfixtureDef:b2FixtureDef = new b2FixtureDef();
dynamicfixtureDef.shape = dynamicBox;
dynamicfixtureDef.density = 1.0;
dynamicfixtureDef.friction = 0.3;
_fallingCrate.CreateFixture(dynamicfixtureDef);
trace ("My world has "+_world.GetBodyCount()+" bodies");
}
}
}