Here is my code:
public function Apples() {
for(var count:int=1; count<=10; count++){
var apple = new Apple();
apple.x = Math.random() * stage.stageWidth;
apple.y = Math.random() * stage.stageHeight;
apple.name = count;
stage.addChild(apple);
}
stage.addEventListener(MouseEvent.CLICK, onclick);
function onclick(e:MouseEvent):void{
var displayObject:DisplayObject = (DisplayObject) (e.target);
displayObject.parent.removeChild(displayObject);
}
}
My problem is that I want to be able to figure out when all of the apples have been removed.
I've tried by adding a simple counter on every onclick call, so that once it reaches the same number of apples this is where I can display a game over message, but the problem here is that if you click on the empty stage rather than the apple, then the count still increases.
Is there a way to prevent the user from clicking on the stage, or a way to identify if the stage has been clicked on for an if condition?
Or maybe there's an entirely other way to achieve what I need?
Thanks for your advice.

New Topic/Question
Reply


MultiQuote



|