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

How to reload/reset the stage?

Participant ,
Sep 07, 2015 Sep 07, 2015


This code is an attempt to reset the stage to the original setup however it would only delete everything of the stage and leave it blank, it wont load the items again. what am I missing here?


playLvlAgn.addEventListener(MouseEvent.CLICK, doLevelAgain);

function doLevelAgain(event: MouseEvent): void {

  stage.removeChildren();

  gotoAndPlay(1);

}

TOPICS
ActionScript
1.9K
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

correct answers 1 Correct answer

Participant , Sep 08, 2015 Sep 08, 2015

OK I found the solution. all removeChilds had to be inside the button function. I also had to sent it to frame2 and stop just in case someone attempted to reload the game before it was even started to play.


playLvlAgn.addEventListener(MouseEvent.CLICK, doLevelAgain);

function doLevelAgain(event: MouseEvent): void {

  gotoAndStop(2);

  for (var i: int = 0; i < 3; i++) {

  if (balls.length > 0) {

  ball = balls.pop();

  ball.parent.removeChild(ball);

  trace("if--0c")

  }

  }

  if (stage.contains(playLvlAgn)

...
Translate
LEGEND ,
Sep 07, 2015 Sep 07, 2015

You are missing the part that reloads everything you removed.  It does not happen automatically.

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
Participant ,
Sep 07, 2015 Sep 07, 2015

I wouldn't ask if I knew how.

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
LEGEND ,
Sep 07, 2015 Sep 07, 2015

You are the only one who knows how you added it, so you need to think about how you did that and how it might need to change.  If you had the stuff manually planted on stage and it existed from frame 1, then going to frame 1 is not going to restore it.  If you added the content dynamically then you need to repeat that process.

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
Participant ,
Sep 07, 2015 Sep 07, 2015

Everything gets loaded on frame1. When I say gotoAndPlay(1); should it not

load everything back?

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
LEGEND ,
Sep 07, 2015 Sep 07, 2015

How is everything loaded on frame 1?

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
Participant ,
Sep 07, 2015 Sep 07, 2015

AddChild

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
Participant ,
Sep 08, 2015 Sep 08, 2015

here is the entire code for frame1. in an attempt to reset the game after it was played.I added if(stage.contains(name)){ removeChild(name);}before anyaddChild(name);  Alas it appears that it totally ignores the if statements but it doesn't ignores the addChild , so it adds more items on top of the existing one. why is it not responding to the if and removeChild?



var score: int = 100;

var bcktcnt: int = 0;

scoreBoard.text = "" + score.toString();

var playLvlAgn: PlayLevelAgain = new PlayLevelAgain();

buttonA.addEventListener(MouseEvent.CLICK, release8Ball1);

buttonC.addEventListener(MouseEvent.CLICK, release8Ball2);

buttonB.addEventListener(MouseEvent.CLICK, release8Ball3);

//playLvlAgn.addEventListener(MouseEvent.CLICK, playAgain);

var yesh8bomb26: bomb26 = new bomb26();

var yesh8bomb27: bomb27 = new bomb27();

var yesh8bomb28: bomb28 = new bomb28();

var yesh8bomb2: bomb1 = new bomb1();

var yesh8bomb3: bomb1 = new bomb1();

var yesh8wall5: wall5 = new wall5();

var yesh8step: step = new step();

var yesh8allBuckets1: allBuckets = new allBuckets();

var yesh8allBuckets2: allBuckets = new allBuckets();

var yesh8DoorA: DoorA = new DoorA();

var yesh8DoorB: DoorB = new DoorB();

var yesh8DoorC: DoorC = new DoorC();

var add8bigGrayBall6: bigGrayBall6 = new bigGrayBall6();

var yesh8redHalfSwing: redHalfSwing = new redHalfSwing();

var yesh8gBall21: gBall21 = new gBall21();

var yesh8gBall24: gBall24 = new gBall24();

if (stage.contains(playLvlAgn)) {

  removeChild(playLvlAgn);

  trace("if--1")

}

addChild(playLvlAgn);

playLvlAgn.x = 122.80;

playLvlAgn.y = 387.10;

if (stage.contains(yesh8DoorA)) {

  removeChild(yesh8DoorA);

  trace("if--2")

}

addChild(yesh8DoorA);

yesh8DoorA.x = 255.6;

yesh8DoorA.y = 134.1;

yesh8DoorA.gotoAndStop(1);

if (stage.contains(yesh8DoorB)) {

  removeChild(yesh8DoorB);

  trace("if--3")

}

addChild(yesh8DoorB);

yesh8DoorB.x = 398.1;

yesh8DoorB.y = 126.5;

yesh8DoorB.gotoAndStop(1);

if (stage.contains(yesh8DoorC)) {

  removeChild(yesh8DoorC);

  trace("if--4")

}

addChild(yesh8DoorC);

yesh8DoorC.x = 288.85;

yesh8DoorC.y = 126.50;

yesh8DoorC.gotoAndStop(1);

if (stage.contains(yesh8allBuckets1)) {

  removeChild(yesh8allBuckets1);

  trace("if--5")

}

addChild(yesh8allBuckets1);

yesh8allBuckets1.x = 325;

yesh8allBuckets1.y = 324.95;

yesh8allBuckets1.gotoAndStop(1);

if (stage.contains(yesh8allBuckets2)) {

  removeChild(yesh8allBuckets2);

  trace("if--6")

}

addChild(yesh8allBuckets2);

yesh8allBuckets2.x = 197.75;

yesh8allBuckets2.y = 324.95;

yesh8allBuckets2.gotoAndStop(1);

if (stage.contains(add8bigGrayBall6)) {

  removeChild(add8bigGrayBall6);

  trace("if--7")

}

addChild(add8bigGrayBall6);

add8bigGrayBall6.x = 420.75;

add8bigGrayBall6.y = 120.80;

add8bigGrayBall6.gotoAndStop(1);

if (stage.contains(yesh8wall5)) {

  removeChild(yesh8wall5);

  trace("if--8")

}

addChild(yesh8wall5);

yesh8wall5.x = 431.30

yesh8wall5.y = 258.50;

if (stage.contains(yesh8step)) {

  removeChild(yesh8step);

  trace("if--9")

}

addChild(yesh8step);

yesh8step.x = 371.35;

yesh8step.y = 262.60;

yesh8step.gotoAndStop(1);

if (stage.contains(yesh8bomb26)) {

  removeChild(yesh8bomb26);

  trace("if--10")

}

addChild(yesh8bomb26);

yesh8bomb26.x = 321.3;

yesh8bomb26.y = 109.85;

yesh8bomb26.gotoAndStop(1);

if (stage.contains(yesh8bomb2)) {

  removeChild(yesh8bomb2);

  trace("if--11")

}

addChild(yesh8bomb2);

yesh8bomb2.x = 421.15;

yesh8bomb2.y = 82.15;

if (stage.contains(yesh8bomb3)) {

  removeChild(yesh8bomb3);

  trace("if--12")

}

addChild(yesh8bomb3);

yesh8bomb3.x = 421.15;

yesh8bomb3.y = 41.70;

if (stage.contains(yesh8gBall21)) {

  removeChild(yesh8gBall21);

  trace("if--13")

}

addChild(yesh8gBall21);

yesh8gBall21.x = 306.35;

yesh8gBall21.y = 128.25;

yesh8gBall21.gotoAndStop(1);

if (stage.contains(yesh8gBall24)) {

  removeChild(yesh8gBall24);

  trace("if--14")

}

addChild(yesh8gBall24);

yesh8gBall24.x = 241.9;

yesh8gBall24.y = 129;

yesh8gBall24.gotoAndStop(1);

if (stage.contains(yesh8redHalfSwing)) {

  removeChild(yesh8redHalfSwing);

  trace("if--15")

}

addChild(yesh8redHalfSwing);

yesh8redHalfSwing.x = 306.35;

yesh8redHalfSwing.y = 128.25;

yesh8redHalfSwing.gotoAndStop(1);

var balls: Array = [],

  ball: gBall4M;

for (var i: int = 0; i < 3; i++) {

  ball = new gBall4M();

  ball.x = 242;

  ball.y = 95 + i * 17;

  balls.push(ball);

  addChild(ball);

}

function release8Ball1(event: MouseEvent): void {

  yesh8DoorA.gotoAndPlay(1);

  gotoAndPlay(2);

  this.addEventListener(Event.ENTER_FRAME, handleCollision);

  this.addEventListener(Event.ENTER_FRAME, handleCollision6);

}

function release8Ball2(event: MouseEvent): void {

  yesh8DoorC.gotoAndPlay(1);

  gotoAndPlay(111);

  this.addEventListener(Event.ENTER_FRAME, handle8Collision3);

  this.addEventListener(Event.ENTER_FRAME, handle8Collision5);

}

function release8Ball3(event: MouseEvent): void {

  yesh8DoorB.gotoAndPlay(1);

  gotoAndPlay(201);

}

playLvlAgn.addEventListener(MouseEvent.CLICK, doLevelAgain);

function doLevelAgain(event: MouseEvent): void {

  gotoAndPlay(1);

}

stop();

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
Participant ,
Sep 08, 2015 Sep 08, 2015
LATEST

OK I found the solution. all removeChilds had to be inside the button function. I also had to sent it to frame2 and stop just in case someone attempted to reload the game before it was even started to play.


playLvlAgn.addEventListener(MouseEvent.CLICK, doLevelAgain);

function doLevelAgain(event: MouseEvent): void {

  gotoAndStop(2);

  for (var i: int = 0; i < 3; i++) {

  if (balls.length > 0) {

  ball = balls.pop();

  ball.parent.removeChild(ball);

  trace("if--0c")

  }

  }

  if (stage.contains(playLvlAgn)) {

  removeChild(playLvlAgn);

  trace("if--1")

  }

  if (stage.contains(yesh8DoorA)) {

  removeChild(yesh8DoorA);

  trace("if--2")

  }

  if (stage.contains(yesh8DoorB)) {

  removeChild(yesh8DoorB);

  trace("if--3")

  }

  if (stage.contains(yesh8DoorC)) {

  removeChild(yesh8DoorC);

  trace("if--4")

  }

  if (stage.contains(yesh8allBuckets1)) {

  removeChild(yesh8allBuckets1);

  trace("if--5")

  }

  if (stage.contains(yesh8allBuckets2)) {

  removeChild(yesh8allBuckets2);

  trace("if--6")

  }

  if (stage.contains(add8bigGrayBall6)) {

  removeChild(add8bigGrayBall6);

  trace("if--7")

  }

  if (stage.contains(yesh8wall5)) {

  removeChild(yesh8wall5);

  trace("if--8")

  }

  if (stage.contains(yesh8step)) {

  removeChild(yesh8step);

  trace("if--9")

  }

  if (stage.contains(yesh8bomb26)) {

  removeChild(yesh8bomb26);

  trace("if--10")

  }

  if (stage.contains(yesh8bomb27)) {

  removeChild(yesh8bomb27);

  trace("if--10")

  }

  if (stage.contains(yesh8bomb28)) {

  removeChild(yesh8bomb28);

  trace("if--10")

  }

  if (stage.contains(yesh8bomb2)) {

  removeChild(yesh8bomb2);

  trace("if--11")

  }

  if (stage.contains(yesh8bomb3)) {

  removeChild(yesh8bomb3);

  trace("if--12")

  }

  if (stage.contains(yesh8gBall21)) {

  removeChild(yesh8gBall21);

  trace("if--13")

  }

  if (stage.contains(yesh8gBall24)) {

  removeChild(yesh8gBall24);

  trace("if--14")

  }

  if (stage.contains(yesh8redHalfSwing)) {

  removeChild(yesh8redHalfSwing);

  trace("if--15")

  }

  gotoAndPlay(1);

}

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