6 Replies Latest reply on Nov 9, 2007 9:41 AM by Rothrock

    UnloadMovie problems

    Patronise Level 1
      My problem is that I'm wrestling to make the LoadMovie and UnloadMovie functions work for me. Here is the layout of my flash file: I've got several seperate flash files and I can jump to any one of them by pressing a specific key to load another flash file. Here is the code I'm using for this bit:

      quote:

      keylistener = new Object();
      keylistener.onKeyDown = function() {
      if (Key.getAscii() == 51)
      loadMovie("tap.swf", "_level1");
      };
      Key.addListener(keylistener);



      Now when the next flash file is loaded, I use this bit of code to get rid of the previous flash file.

      quote:

      unloadMovie("_level0");


      Now this does work in getting rid of the previous flash file in a visual sense; it dissapears, but the code still remains active. See, I have several other keypress functions in each flash file, so I need to disable/remove/unload the programmed keypresses of the previous scene. Because at the moment I'm getting stuff like this: I'll press a key and move from flash file "tip" to flash file "top," but then I press the Q key, which is meant to make a character pop up in the flash file "top," but it ends up taking me back to the flash file "tip," because that also has coding attached to the Q key.

      Phew, hopes this makes sense. I've found out that people can get around this problem when working with buttons and making the buttons disabled...but can you do a similar thing with key presses? Is there perhaps another way to open flash files in the time line other than the LoadMovie code?

      Oh, and I'm working in Flash MX Professional 2004

      Cheers,
      Kyle
        • 1. Re: UnloadMovie problems
          Juankpro Level 2
          Where are you writting the unloadMovie code
          • 2. Re: UnloadMovie problems
            Patronise Level 1
            Oh I've been placing it at different points to see the effect. I think I've put it in the preloader, at the end of the previous flash file, at the start of the next flash file and in the middle of flash files. All positions have the same problem.
            • 3. Re: UnloadMovie problems
              Patronise Level 1
              All is well, I found a solution on another forum!
              Odd, but it seems that unloadMovie("_level1"); has problems that unloadMovieNum(1); doesn't.
              Although it seems I have to be careful not to unload level 0 - if you unload that everything dissapears!
              • 4. Re: UnloadMovie problems
                Juankpro Level 2
                Yep because the level 0 is the one containing everything. So you need initially a Flash movie that only loads the main content con level 1.
                • 5. UnloadMovie problems
                  bartonsmith Level 1
                  I have a similar problem but can't seem to solve it with these solutions.

                  I have 2 files intro.swf and content.swf.
                  Intro.swf has an opening animation that loads straight away so there is no need for a preloader. At the end of the animation I use loadMovie to load content.swf into an empty MC.
                  Content.swf shows the final frame of intro.swf and also has a preloader for the rest of the stuff to be loaded. Once the preloader has finished loading an "enter" button appears.

                  This is where the problem lies.

                  I want those final frames (either the layers or mcs) from intro.swf to be removed when the user clicks "enter" so that when the rest of the content.swf stuff loads, the intro.swf mcs do not overlay them.


                  What I have tried so far:

                  unloadMovie(_parent); unloadMovie(_root); unloadMovie("_level0"); - these remove everything including content.swf (but that is because content.swf is loaded into/a part of intro.swf)
                  I also tried loading intro.swf into a blank swf and then content.swf into intro.swf and use unloadMovie("_level1") but this does the same thing.
                  I tried a few variations of the same thing from around the net but no luck.

                  Any ideas?
                  Or have I just gone about my preloader incorrectly?

                  Cheers
                  Barton


                  http://members.optusnet.com.au/expansiondesign/Website%20V6/intro1.4.swf
                  It's the static background lines and the expansiondesign text that I want to remove after pressing enter.
                  It loads really quickly cos there is nothing much to load atm.
                  • 6. Re: UnloadMovie problems
                    Rothrock Level 5
                    Well you are (maybe) learning some good stuff about the proper uses of loadMovie()/unloadMovie() and loadMovieNum()/unloadMovieNum(). If you are loading/unloading into Levels you should use the "Num" version of boh of those. However I have some other thoughts for you.

                    Unless you are publishing to Flash 6 or earlier, you should probably look into using the MovieClipLoader class. It is much better for this type of thing.

                    Second, in general I find _levels hard to work with and never use them. They aren't addressable until content has been loaded and since they aren't really a class of their own they don't have many ways to work with them. They have even gone away in AS3 and are no longer an option. So I would suggest not using them.

                    Finally, the real problem is that the Key listener keeps listening even after the clip that makes it is removed. So if you want to make it stop, then that is what you have to do!

                    keylistener = new Object();
                    keylistener.onKeyDown = function() {
                    if (Key.getAscii() == 51)
                    Key.removeListener(keylistener);
                    loadMovie("tap.swf", "_level1");
                    };
                    Key.addListener(keylistener);

                    Notice that I remove the listener. That doesn't have to be done inside the onKeyDown event handler, but that is generally a good place for it.