Game over screen problem
For a while I've been working on a flashgame but not I'm stuck. I am a beginner with Flash, so if I've made a stupid mistake and waste your time I am terribly sorry. The problem I am having is that after having a score that is lesser than 0, you cannot "remove" the game over screen. I'd love to have the game restart as soon as the game over menu is deleted, but so far I've had no success. Below is the code for the main script, followed by the game over screen code. Hope someone can help me with setting the alpha for the menu back to 0 as soon as the mouse is pressed.
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Game extends MovieClip{
var score = 0;
var replay = 0;
public function Game() {
udead.alpha = 0;
addEventListener(Event.ENTER_FRAME, testListener);
addEventListener(Event.ENTER_FRAME, checkForHitNet1);
addEventListener(Event.ENTER_FRAME, checkForHitNet2);
addEventListener(Event.ENTER_FRAME, checkForHitPole1a);
addEventListener(Event.ENTER_FRAME, checkForHitPole1b);
addEventListener(Event.ENTER_FRAME, KILLER);
addEventListener(MouseEvent.CLICK, replay);
stage.addEventListener(MouseEvent.MOUSE_DOWN, CLICK);
}
public function checkForHitNet1(event:Event) {
if ( ball.hitTestObject( net ) ) {
this.removeChild(net);
score += 1;
scorefield.text = score;
}
}
public function checkForHitNet2(event:Event) {
if ( ball.hitTestObject( net2 ) ) {
this.removeChild(net2);
score += 1;
scorefield.text = score;
}
}
public function checkForHitPole1a(event:Event) {
if ( ball.hitTestObject( pole ) ) {
this.removeChild(pole);
score -= 1;
scorefield.text = score;
}
}
public function checkForHitPole1b(event:Event) {
if ( ball.hitTestObject( pole2 ) ) {
this.removeChild(pole2);
score -= 1;
scorefield.text = score;
}
}
public function testListener(event:Event) {
trace ('pleh');
}
public function KILLER (event:Event) {
if (score < 0 ) {
udead.alpha = 100;
this. removeChild(net);
this.removeChild(net2);
this.removeChild(pole);
this.removeChild(pole2);
this.removeChild(ball);
scorefield.text = score;
}
if(score < 0 && MouseEvent.CLICK == true) {
udead.alpha = 0;
score = 0;
replay = 1;
trace ('finally');
}
}
}
}
And here's the script for the game over screen:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Udead extends MovieClip {
public function Udead() {
addEventListener(Event.ENTER_FRAME, replay);
stage.addEventListener(MouseEvent.CLICK, replay);
}
public function replay (event:MouseEvent){
trace ('mouse');
if(score < 0 && MouseEvent.CLICK == true) {
udead.alpha = 0;
trace ('boop');
score = 0;
}
}
}
}
I hope someone is willing to help me. Thanks in advance!
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width