Background: Trying to make a ball appear in the same location the mouse is positioned. Using Box2D Library. Working on a class file (.as)
Issue: The mouse event does not work (I click but nothing happens) . No output errors whatsoever. :(
Mouse Event:
private function _clicked(e:MouseEvent)
{
sim.addCircle({x:mouseX, y:mouseY, radius:0.25, density:5});
sim.start();
Full Code:
package {
import flash.display.MovieClip;
import com.actionsnippet.qbox.*;
import flash.events.MouseEvent;
[SWF(width = 350, height = 600, frameRate = 60)]
public class MouseTest extends MovieClip {
public var sim:QuickBox2D;
/**
* Constructor
*/
public function MouseTest()
{
sim = new QuickBox2D(this);
sim.createStageWalls();
addEventListener(MouseEvent.CLICK, _clicked);
}
/**
* ..
* @param e MouseEvent.CLICK
*/
private function _clicked(e:MouseEvent)
{
sim.addCircle({x:mouseX, y:mouseY, radius:0.25, density:5});
sim.start();
}
}
}
Download Project (BOX2D Included)
stage.addEventListener(MouseEvent.CLICK, _clicked)
in your constructor instead ofaddEventListener(MouseEvent.CLICK, _clicked)
. Probably should also callsuper()
on the first line of your constructor as well. \$\endgroup\$