BOX2D and AS3: Mouse Event not working
- by Gabriel Meono
Background:
Trying to make a simple "drop the ball" game.
The code is located inside the first frame of the timeline. Nothing more is on the stage.
Issue:
Using QuickBox2D I made a simple If statement that drops and object acording the Mouse-x position:
if (MouseEvent.CLICK) {
sim.addCircle({x:mouseX, y:1, radius:0.25, density:5});
I imported the MouseEvent library:
import flash.events.MouseEvent;
Nothing happens if I click, no output errors either.
See it in action:
http://gabrielmeono.com/download/Lucky_Hit_Alpha.swf
http://gabrielmeono.com/download/Lucky_Hit_Alpha.fla
Full Code:
[SWF(width = 350, height = 600, frameRate = 60)]
import com.actionsnippet.qbox.*;
import flash.events.MouseEvent;
var sim:QuickBox2D = new QuickBox2D(this);
sim.createStageWalls();
//var ball:sim.addCircle({x:mouseX, y:1, radius:0.25, density:5}); //
// make a heavy circle
sim.addCircle({x:3, y:1, radius:0.25, density:5});
sim.addCircle({x:2, y:1, radius:0.25, density:5});
sim.addCircle({x:4, y:1, radius:0.25, density:5});
sim.addCircle({x:5, y:1, radius:0.25, density:5});
sim.addCircle({x:6, y:1, radius:0.25, density:5});
// create a few platforms
sim.addBox({x:3, y:2, width:4, height:0.2, density:0, angle:0.1});
// make 26 dominoes
for (var i:int = 0; i<7; i++){
//End
sim.addCircle({x:1 + i * 1.5, y:16, radius:0.1, density:0});
sim.addCircle({x:2 + i * 1.5, y:15, radius:0.1, density:0});
//Mid end
sim.addCircle({x:0 + i * 2, y:14, radius:0.1, density:0});
sim.addCircle({x:0 + i * 2, y:13, radius:0.1, density:0});
sim.addCircle({x:0 + i * 2, y:12, radius:0.1, density:0});
sim.addCircle({x:0 + i * 2, y:11, radius:0.1, density:0});
sim.addCircle({x:0 + i * 2, y:10, radius:0.1, density:0});
//Middle Start
sim.addCircle({x:0 + i * 1.5, y:09, radius:0.1, density:0});
sim.addCircle({x:1 + i * 1.5, y:08, radius:0.1, density:0});
sim.addCircle({x:0 + i * 1.5, y:07, radius:0.1, density:0});
sim.addCircle({x:1 + i * 1.5, y:06, radius:0.1, density:0});
}
if (MouseEvent.CLICK) {
sim.addCircle({x:mouseX, y:1, radius:0.25, density:5});
sim.start();
/*sim.mouseDrag();*/
}