Copy link to clipboard
Copied
I'm creating a game over screen and there is a retry button on it, when that button is clicked, the game over screen remove itself and jump to the main screen so player could restart it. When the retry button is clicked for the first time, it works fine, the game over screen is gone. But when it is clicked for the second time, the game over screen is here again, it just keeps coming back after the first retry. It seems the unload works for the first time only. Any help is greatly appreciated!
public class GameOverMenu extends BaseMenu {
public function GameOverMenu(stageRef: Stage = null) {
this.stageRef = stageRef;
btnRetry.addEventListener(MouseEvent.MOUSE_DOWN, returnMainMenu, false, 0, true);
}
private function returnMainMenu(e: MouseEvent😞 void {
unload(new MainMenu(stageRef));
}
}
Copy link to clipboard
Copied
what's unload()?
Copy link to clipboard
Copied
Yes public class BaseMenu extends MovieClip { |
public var stageRef: Stage; | ||
public var loadNext: BaseMenu; |
public function BaseMenu() { | |||
alpha = 0; | |||
y = 1334; | |||
} |
public function unload(loadMe: BaseMenu = null): void { | ||||
if (loadMe != null) | ||||
loadNext = loadMe; |
Tweener.addTween(this, { | |||||
alpha: 0, | |||||
| |||||
| |||||
onComplete: remove | |||||
}); | |||||
} |
public function remove(): void { | ||||
if (stageRef.contains(this)) | ||||
stageRef.removeChild(this); |
if (loadNext != null) | ||||
loadNext.load(); | ||||
} |
public function load(): void { | ||||
stageRef.addChild(this); | ||||
Tweener.addTween(this, { | ||||
alpha: 1, | ||||
y: 0, | ||||
time: 0.2 | ||||
}); | ||||
} |
} |
Copy link to clipboard
Copied
that's quite a mess. no wonder you're having a problem.
use some trace statements to see which BaseMenu instance you're trying to remove and which unload method you're calling.
Copy link to clipboard
Copied
Thanks, the GameOverMenu instance is the one I'm trying to remove.
if (loadMe != null)
loadNext = loadMe;
If loadMe gets something passed into it, then it will store it in loadNext. In this case, the GameOverMenu instance. And below is the function I'm calling.
public function unload(loadMe:BaseMenu = null) : void
Copy link to clipboard
Copied
this is really a mess and should be re-done.
but the best i can determine this might work:
public class GameOverMenu extends BaseMenu {
public function GameOverMenu(stageRef: Stage = null) {
this.stageRef = stageRef;
btnRetry.addEventListener(MouseEvent.MOUSE_DOWN, returnMainMenu, false, 0, true);
}
private function returnMainMenu(e: MouseEvent): void {
unload(new MainMenu(stageRef),this);
}
}
public class BaseMenu extends MovieClip { |
public var stageRef: Stage; | ||
public var loadNext: BaseMenu; |
private ver unloadMenu:GameOverMenu;
public function BaseMenu() { | |||
alpha = 0; | |||
y = 1334; | |||
} |
public function unload(loadMe: BaseMenu = null,gameOverMenu:GamerOverMenu=null): void { | ||||
if (loadMe != null) | ||||
loadNext = loadMe; |
if(gameOverMenu){
unloadMenu=gameOverMenu;
Tweener.addTween(unloadMenu, { | |||||
alpha: 0, | |||||
| |||||
| |||||
onComplete: remove | |||||
}); | |||||
} | } |
public function remove(): void { | ||||
if (unloadMenu&unloadMenu.stage){ | ||||
unloadMenu.parent.removeChild(unloadMenu); |
unloadMenu=null
}
if (loadNext != null) | ||||
loadNext.load(); | ||||
} |
public function load(): void { these 'this' references probably shoudl be loadNext | ||||
stageRef.addChild(this); | ||||
Tweener.addTween(this, { | ||||
alpha: 1, | ||||
y: 0, | ||||
time: 0.2 | ||||
}); | ||||
} |
} |
Find more inspiration, events, and resources on the new Adobe Community
Explore Now