Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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();*/  




    }
share|improve this question
add comment

1 Answer

You can't catch mouse-events like that. You have to add an event listener, like this:

function handleClick(evt:MouseEvent):void
{
    sim.addCircle({x:mouseX, y:1, radius:0.25, density:5});
}

addEventListener(MouseEvent.CLICK, handleClick);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.