Skip to main content
Inspiring
December 29, 2012
Answered

why is my swf loading the wrong swf file even though the url is correct?

  • December 29, 2012
  • 1 reply
  • 2522 views

I am creating a game that consist of multiple external SWF files that I connected using the loader class. I have 3 levels. At first the connection of the swf is woking well. But after finishing level 2, when the congratulatory screen appears and then pressed the button so that I can proceed to the next level, it goes back to level 2 instead of proceeding to Level 3. >.< When I check the URL, it is correct.

This topic has been closed for replies.
Correct answer kglad

i have deleted the unload code and used only one loader but still the stage2.swf loads the congratulatory_screen_1.swf even though the url i used is supposed to load the congratulatory_screen_2.swf. this happens when i load it from the first level but when i load it from stage2.swf it correctly loads the next swf. why is that?


assuming the top snippet is stage2.swf and it loads a congratuloary.swf that uses that 2nd snippet, your code shows stage2.swf loading congratulatory.swf and congratulotory.swf loading stage2.swf and that's a problem.  fix that.

1 reply

kglad
Community Expert
Community Expert
December 29, 2012

copy and paste the relevant code.

Inspiring
December 29, 2012

Here is the code.

On the Congratulatory Screen where there is a button connected to Stage3:

next_stage.addEventListener(MouseEvent.CLICK, loadStage_2);

var music_1:Sound = new Sound(new URLRequest("Congrats_Theme.mp3"));

music_1.play();

function loadStage_2(event:MouseEvent):void

           {

     var myrequest:URLRequest=new URLRequest("Stage3.swf");

     var myloader:Loader=new Loader();

     myloader.addEventListener("UnloadMe", unloadFunction);

     myloader.load(myrequest);

     stage.addChild(myloader);

           removeChildAt(0);

           removeChild(next_stage);

           SoundMixer.stopAll();

     }

          

function unloadFunction(event:Event):void {

Loader(event.currentTarget).unload();

}

Level 2 code:

if (fl_SecondsElapsed == 0 && score >= 70)

                                                            {

                                                                      stopGame();

                                                                      var myrequest:URLRequest = new URLRequest("Congratulatory_Screen_2.swf");

                                                                      var myloader:Loader = new Loader();

                                                                      myloader.addEventListener("UnloadMe", unloadFunction);

                                                                      myloader.load(myrequest);

                                                                      SoundMixer.stopAll();

                                                                      stage.addChild(myloader);

                                                                      removeChild(Score_board);

                                                                      removeChild(Timer_board);

                                                                      removeChild(ScoreDisplay);

                                                                      removeChild(TimerDisplay);

                                                            }

 

                                                            else if (fl_SecondsElapsed == 0 && score < 70)

                                                            {

                                                                      stopGame();

                                                                      var myrequest1:URLRequest = new URLRequest("Game_Over_2.swf");

                                                                      var myloader1:Loader = new Loader();

                                                                      myloader1.addEventListener("UnloadMe", unloadFunction_1);

                                                                      myloader1.load(myrequest1);

                                                                      SoundMixer.stopAll();

                                                                      stage.addChild(myloader1);

                                                                      removeChild(Score_board);

                                                                      removeChild(Timer_board);

                                                                      removeChild(ScoreDisplay);

                                                                      removeChild(TimerDisplay);

                                                            }

                                                            }

                                                            public function unloadFunction(event:Event) {

                                                               Loader(event.currentTarget).unloadAndStop();

                                                            }

 

                                                            public function unloadFunction_1(event:Event) {

                                                               Loader(event.currentTarget).unloadAndStop();

                                                            }