Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 Unload Problem

Explorer ,
Mar 14, 2016 Mar 14, 2016

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));
  
}

}

TOPICS
ActionScript
396
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2016 Mar 14, 2016

what's unload()?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2016 Mar 14, 2016

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,
y: -1334,
time: 0.2,
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
});
}

}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2016 Mar 14, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 15, 2016 Mar 15, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 15, 2016 Mar 15, 2016
LATEST

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,
y: -1334,
time: 0.2,
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
});
}

}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines