7 Replies Latest reply on Jan 12, 2010 8:13 AM by Ned Murphy

    unload movieclip

    Wheeler Labs Level 1

      I have a button running the following:

      on (rollover) {
      this.attachMovie("coastal_mc", "window", 1);
      window._x = 150;
      window._y = 150;
      }


      which loads an image next to the button. what i need to add is something that says "on any other event after this event, unload this movieclip" because right now, once you press it, it loads, but if you press another nav button the image stays there and doesnt unload.

      thx

        • 1. Re: unload movieclip
          Ned Murphy Adobe Community Professional & MVP

          To remove a movieclip that has been added using the attachMovie() method you use the removeMovieClip method.  So you would need to have that removal code assigned to any other interactive thing you would need to, such as the other buttons you mention.  What you should do is also have a boolean value that keeps track of whether or not the movieclip is present or not, so that clicking a button won't be attempting to remove the attached movie unless it exists.  The attaching code would set that value true, otherwise it would be set false.. as in...

           

          var movieAttached = false;

           

          // your current code

          on (rollover) {
          this.attachMovie("coastal_mc", "window", 1);
          window._x = 150;
          window._y = 150;

          movieAttached = true;
          }

           

          //one of your buttons...

          on(release){

               if(movieAttached){

                    //remove it then change the var to false again

                    movieAttached = false;

               }

          1 person found this helpful
          • 2. Re: unload movieclip
            Wheeler Labs Level 1

            thanks ned. i was hoping there was a way to do this without assigning the code to all the other buttons since there are a lot.

            • 3. Re: unload movieclip
              Ned Murphy Adobe Community Professional & MVP

              You can have a single function that provides the removal activity, but you'd still need to have code in each interactive element for executing that function.

              1 person found this helpful
              • 4. Re: unload movieclip
                Wheeler Labs Level 1

                Ned,

                 

                Can you please post the code you mentioned without your comments embedded so i can cut and paste? i'm clueless enough to not completely know what you mean.

                 

                the code for the button and the code for the other buttons that should unload.

                 

                thx

                • 5. Re: unload movieclip
                  Ned Murphy Adobe Community Professional & MVP

                  Often you have to look things up in the help files to understand how to use them.  As requested, code with comments removed...

                   

                  var movieAttached = false;

                   

                  function removeWindow(){
                       if(movieAttached){
                           window.removeMovieClip();
                           movieAttached = false;
                      }
                  }

                   

                  on (rollover) {
                        this.attachMovie("coastal_mc", "window", 1);
                        window._x = 150;
                        window._y = 150;
                        movieAttached = true;
                  }


                  on(release){
                       removeWindow();
                  }

                  1 person found this helpful
                  • 6. Re: unload movieclip
                    Wheeler Labs Level 1

                    which parts of the code go on which element? what is in the empty parentheses?

                    • 7. Re: unload movieclip
                      Ned Murphy Adobe Community Professional & MVP

                      You asked me to remove the comments.  Try going back to the code I commented earlier and see if you can figure it out.