Newbie Requiring Aid!!

Hey, I'm extremely new to Box2D, and have been trying to work through the examples and tutorials for the past couple days.

I still can't seem to figure out some of the most basic things. The main thing I'm trying to go for is that when the mouse is clicked, a small box shoots out from it in an upwards direction.

Now, I know how to make the boxes, but how do you detect the users mouse input and position?
Also, in the examples there was the m_PhysScale variable so that when divided by it, it would convert meters to pixels. Where is m_PhysScale declared or where does it come from?

I know AS3 fairly well, but am not used to all this external linking of separate files as I'm used to working with 1 single .fla with all my actionscript. Any help would be appreciated, I'm lost in this wealth of knowledge!!
Thanks for the help so far.

"look for Eventhandlers like
MouseEvent.MOUSE_MOVE
MouseEvent.MOUSE_DOWN
MouseEvent.MOUSE_UP"


I know those, but how do you ACTUALLY use it in the code. Every way I know from my AS3 experience has failed so far (adding an event listener that calls a function).
at the start of your code:
addEventListener(MouseEvent.MouseDown, YourFunction);

YourFunction(e:MouseEvent):void{

Apply impulse...blahblahblah

}
Thanks for that Tip Yager.

This is what I got as of now, based from the HelloWorld example.
Still gets errors such as "Cannot access undefined property BodyDef".
I think I did the mouseEvent function wrong, but I can't sort it out. Sorry for being such a noob, but I'm trying.

Quote:
package{

import flash.display.Sprite;
import flash.events.Event;
import flash.events.*;
// Classes used in this example
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
import Box2D.Common.Math.*;
import General.*;

public class HelloWorld extends Sprite{

public function HelloWorld(){



// Add event for main loop
addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
addEventListener(MouseEvent.MouseDown, clicked);


// Creat world AABB
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-100.0, -100.0);
worldAABB.upperBound.Set(100.0, 100.0);

// Define the gravity vector
var gravity:b2Vec2 = new b2Vec2(0.0, 10.0);

// Allow bodies to sleep
var doSleep:Boolean = true;

// Construct a world object
m_world = new b2World(worldAABB, gravity, doSleep);

// set debug draw
/*
var dbgDraw:b2DebugDraw = new b2DebugDraw();
var dbgSprite:Sprite = new Sprite();
addChild(dbgSprite);
dbgDraw.m_sprite = dbgSprite;
dbgDraw.m_drawScale = 30.0;
dbgDraw.m_fillAlpha = 0.0;
dbgDraw.m_lineThickness = 1.0;
dbgDraw.m_drawFlags = 0xFFFFFFFF;
m_world.SetDebugDraw(dbgDraw);
*/



// Vars used to create bodies
var body:b2Body;
var bodyDef:b2BodyDef;
var boxDef:b2PolygonDef;
var circleDef:b2CircleDef;



// Add ground body
bodyDef = new b2BodyDef();
//bodyDef.position.Set(15, 19);
bodyDef.position.Set(10, 12);
//bodyDef.angle = 0.1;
boxDef = new b2PolygonDef();
boxDef.SetAsBox(30, 3);
boxDef.friction = 0.3;
boxDef.density = 0; // static bodies require zero density
/*
circleDef = new b2CircleDef();
circleDef.radius = 10;
circleDef.restitution = 0.2
*/
// Add sprite to body userData
bodyDef.userData = new PhysGround();
//bodyDef.userData = new PhysCircle();
bodyDef.userData.width = 30 * 2 * 30;
bodyDef.userData.height = 30 * 2 * 3;
addChild(bodyDef.userData);
body = m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
//body.CreateShape(circleDef);
body.SetMassFromShapes();

// Add some objects
}

}

public function clicked(e:MouseEvent):void {
for (var i:int = 1; i < i+1; i++){
bodyDef = new b2BodyDef();
// Box
boxDef = new b2PolygonDef();
boxDef.SetAsBox(0.25, 0.25);
boxDef.density = 1.0;
boxDef.friction = 0.5;
boxDef.restitution = 0.2;
bodyDef.position.Set(330/30, 180/30);
bodyDef.userData = new PhysBox();
bodyDef.userData.width = 15;
bodyDef.userData.height = 15;
body = m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
i++

/*// Circle
else {
circleDef = new b2CircleDef();
circleDef.radius = rX;
circleDef.density = 1.0;
circleDef.friction = 0.5;
circleDef.restitution = 0.2
bodyDef.userData = new PhysCircle();
bodyDef.userData.width = rX * 2 * 30;
bodyDef.userData.height = rX * 2 * 30;
body = m_world.CreateBody(bodyDef);
body.CreateShape(circleDef);
}*/

body.SetMassFromShapes();
addChild(bodyDef.userData);
}
}

public function Update(e:Event):void{

m_world.Step(m_timeStep, m_iterations);


// Go through body list and update sprite positions/rotations
for (var bb:b2Body = m_world.m_bodyList; bb; bb = bb.m_next){
if (bb.m_userData is Sprite){
bb.m_userData.x = bb.GetPosition().x * 30;
bb.m_userData.y = bb.GetPosition().y * 30;
bb.m_userData.rotation = bb.GetAngle() * (180/Math.PI);
}
}

}

public var m_world:b2World;
public var m_iterations:int = 10;
public var m_timeStep:Number = 1.0/30.0;


}
putting these:
var body:b2Body;
var bodyDef:b2BodyDef;
var boxDef:b2PolygonDef;
var circleDef:b2CircleDef;

next to:
public var m_world:b2World;
public var m_iterations:int = 10;
public var m_timeStep:Number = 1.0/30.0;

may help and make them public so:
Code:
public var m_world:b2World;
public var m_iterations:int = 10;
public var m_timeStep:Number = 1.0/30.0;
public var body:b2Body;
public var bodyDef:b2BodyDef;
public var boxDef:b2PolygonDef;
public var circleDef:b2CircleDef;
Ah thanks a ton, that helped a lot of things. Now everything seems in place, but I'm still getting this error.

5006: An ActionScript file can not have more than one externally visible definition: circleDef, bodyDef??

Now I have no clue whatsoever of what that one means.
That has to do with how you've set up your folders i think, do you have 2 instances of bodyDef and circleDef somewhere or have you perhaps added the box2d library twice?
Recently i was playing with mouse interactions in order to remove a "block" from the simulation. The Testbed does this by using an external class called General.Input (which has alot of compiler warnings but works). You should be able to hack around with the already written methods of the test bed to get your desired functionality.

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