8 Replies Latest reply: Aug 29, 2011 4:02 PM by kglad RSS

    Help Please! Movies play in background!

    EGBAR.Mary Community Member

      Help Please! I am very new at this. I have a random movie playing in a window and 6 buttons below-each plays its own movie when clicked. The problem is that as you clck around on the buttons, a movie plays in the background. I did get the sound to stop. I appreciate any help.

       

      import flash.display.MovieClip;

      import flash.events.MouseEvent;

      //This is where the Stop Sound is

      function fl_ClickToStopAllSounds(event:MouseEvent):void {

      SoundMixer.stopAll();

      }

       

      var loader:Loader = new Loader(); //this variable will load the file

      var movieList:Array = [ threePrinciples, newlyweds, automotive, manRap, boysToys, troopTradition];

      var mc:MovieClip = getRandomMovie();

      var buttonPrinciples:ButtonPrinciples = new ButtonPrinciples;

      var buttonNewlyweds:ButtonNewlyweds = new ButtonNewlyweds;

      var buttonManRap:ButtonManRap = new ButtonManRap;

      var buttonBoysToys:ButtonBoysToys = new ButtonBoysToys;

      var buttonAuto:ButtonAuto = new ButtonAuto;

      var buttonTroops:ButtonTroops = new ButtonTroops;

       

      //Play Random Movie in Main window

      function getRandomMovie():MovieClip {

        return new movieList[Math.floor(Math.random()*movieList.length)];

      }

       

      addChild(mc);

      mc.x = 34;

      mc.y = 38;

       

       

      //Add Buttons below Main Window

       

      addChild(buttonPrinciples);

      buttonPrinciples.x=34;

      buttonPrinciples.y=312;

      buttonPrinciples.buttonMode = true;

       

      addChild(buttonNewlyweds);

      buttonNewlyweds.x=111.60;

      buttonNewlyweds.y=312;

      buttonNewlyweds.buttonMode = true;

       

      addChild(buttonManRap);

      buttonManRap.x=189.20;

      buttonManRap.y=312;

      buttonManRap.buttonMode = true;

       

      addChild(buttonBoysToys);

      buttonBoysToys.x=266.80;

      buttonBoysToys.y=312;

      buttonBoysToys.buttonMode = true;

       

      addChild(buttonAuto);

      buttonAuto.x=344.40;

      buttonAuto.y=312;

      buttonAuto.buttonMode = true;

       

      addChild(buttonTroops);

      buttonTroops.x=422;

      buttonTroops.y=312;

      buttonTroops.buttonMode = true;

       

       

       

      //If the first button is clicked ThreePrinciples is replaces Random Movie

      buttonPrinciples.addEventListener(MouseEvent.CLICK, button1Clicked);

       

      function button1Clicked(event:MouseEvent):void {

      removeChild:(movieList);

      SoundMixer.stopAll();

       

      var bruce:threePrinciples = new threePrinciples();

      addChild(bruce);

      bruce.x = 34;

      bruce.y = 38;

      //trace("button clicked");

      }

       

       

      //If the second button is clicked newlyweds replaces Random Movie

      buttonNewlyweds.addEventListener(MouseEvent.CLICK, button2Clicked);

       

      function button2Clicked(event:MouseEvent):void {

      unloadMovie:(movieList);

      SoundMixer.stopAll();

       

      var newly:newlyweds = new newlyweds();

      addChild(newly);

      newly.x = 34;

      newly.y = 38;

      //trace("button clicked");

      }

       

      //If the third button is clicked manRap replaces Random Movie

      buttonManRap.addEventListener(MouseEvent.CLICK, button3Clicked);

       

      function button3Clicked(event:MouseEvent):void {

      removeChild:(movieList);

      SoundMixer.stopAll();

       

      var rap:manRap =  new manRap();

      addChild(rap);

      rap.x = 34;

      rap.y = 38;

      //trace("button clicked");

      }

       

      //If the fourth button is clicked boysToys replaces Random Movie

      buttonBoysToys.addEventListener(MouseEvent.CLICK, button4Clicked);

       

      function button4Clicked(event:MouseEvent):void {

      removeChild:(movieList);

      SoundMixer.stopAll();

       

      var toys:boysToys =  new boysToys();

      addChild(toys);

      toys.x = 34;

      toys.y = 38;

      //trace("button clicked");

      }

       

      //If the fifth button is clicked auto replaces Random Movie

      buttonAuto.addEventListener(MouseEvent.CLICK, button5Clicked);

       

      function button5Clicked(event:MouseEvent):void {

      removeChild:(movieList);

      SoundMixer.stopAll();

       

      var auto:automotive =  new automotive();

      addChild(auto);

      auto.x = 34;

      auto.y = 38;

      //trace("button clicked");

      }

       

      //If the sixth button is clicked troops replaces Random Movie

      buttonTroops.addEventListener(MouseEvent.CLICK, button6Clicked);

       

      function button6Clicked(event:MouseEvent):void {

      removeChild:(movieList);

      SoundMixer.stopAll();

       

      var troops:troopTradition =  new troopTradition();

      addChild(troops);

      troops.x = 34;

      troops.y = 38;

      //trace("button clicked");

      }

       

      var myFrame:emptyMC = new emptyMC();

      addChild(myFrame);

      myFrame.x = 33;

      myFrame.y = 37;

       

       

        • 1. Re: Help Please! Movies play in background!
          kglad CommunityMVP

          use:

           


          import flash.display.MovieClip;

          import flash.events.MouseEvent;

          //This is where the Stop Sound is

          function fl_ClickToStopAllSounds(event:MouseEvent):void {

          SoundMixer.stopAll();

          }

           

          var loader:Loader = new Loader(); //this variable will load the file

          var movieList:Array = [ threePrinciples, newlyweds, automotive, manRap, boysToys, troopTradition];

          var mc:MovieClip = getRandomMovie();

          var buttonPrinciples:ButtonPrinciples = new ButtonPrinciples;

          var buttonNewlyweds:ButtonNewlyweds = new ButtonNewlyweds;

          var buttonManRap:ButtonManRap = new ButtonManRap;

          var buttonBoysToys:ButtonBoysToys = new ButtonBoysToys;

          var buttonAuto:ButtonAuto = new ButtonAuto;

          var buttonTroops:ButtonTroops = new ButtonTroops;

           

          //Play Random Movie in Main window

          function getRandomMovie():MovieClip {

            return new movieList[Math.floor(Math.random()*movieList.length)];

          }

           

          addChild(mc);

          var lastAdded_mc:MovieClip=mc;

           

          mc.x = 34;

          mc.y = 38;

           

           

          //Add Buttons below Main Window

           

          addChild(buttonPrinciples);

          buttonPrinciples.x=34;

          buttonPrinciples.y=312;

          buttonPrinciples.buttonMode = true;

           

          addChild(buttonNewlyweds);

          buttonNewlyweds.x=111.60;

          buttonNewlyweds.y=312;

          buttonNewlyweds.buttonMode = true;

           

          addChild(buttonManRap);

          buttonManRap.x=189.20;

          buttonManRap.y=312;

          buttonManRap.buttonMode = true;

           

          addChild(buttonBoysToys);

          buttonBoysToys.x=266.80;

          buttonBoysToys.y=312;

          buttonBoysToys.buttonMode = true;

           

          addChild(buttonAuto);

          buttonAuto.x=344.40;

          buttonAuto.y=312;

          buttonAuto.buttonMode = true;

           

          addChild(buttonTroops);

          buttonTroops.x=422;

          buttonTroops.y=312;

          buttonTroops.buttonMode = true;

           

           

           

          //If the first button is clicked ThreePrinciples is replaces Random Movie

          buttonPrinciples.addEventListener(MouseEvent.CLICK, button1Clicked);

           

          function button1Clicked(event:MouseEvent):void {

          removeChild:(lastAdded_mc);

          lastAdded_mc.stop();

          SoundMixer.stopAll();

           

          var bruce:threePrinciples = new threePrinciples();

          addChild(bruce);

          lastAdded_mc=bruce;

          bruce.x = 34;

          bruce.y = 38;

          //trace("button clicked");

          }

           

           

          //If the second button is clicked newlyweds replaces Random Movie

          buttonNewlyweds.addEventListener(MouseEvent.CLICK, button2Clicked);

           

          function button2Clicked(event:MouseEvent):void {

           

          removeChild:(lastAdded_mc);

          lastAdded_mc.stop();

          SoundMixer.stopAll();

           

          var newly:newlyweds = new newlyweds();

          addChild(newly);

          lastAdded_mc=newly;

          newly.x = 34;

          newly.y = 38;

          //trace("button clicked");

          }

           

          //If the third button is clicked manRap replaces Random Movie

          buttonManRap.addEventListener(MouseEvent.CLICK, button3Clicked);

           

          function button3Clicked(event:MouseEvent):void {

           

          removeChild:(lastAdded_mc);

          lastAdded_mc.stop();

          SoundMixer.stopAll();

           

          var rap:manRap =  new manRap();

          addChild(rap);

          lastAdded_mc=rap;

          rap.x = 34;

          rap.y = 38;

          //trace("button clicked");

          }

           

          //If the fourth button is clicked boysToys replaces Random Movie

          buttonBoysToys.addEventListener(MouseEvent.CLICK, button4Clicked);

           

          function button4Clicked(event:MouseEvent):void {

           

          removeChild:(lastAdded_mc);

          lastAdded_mc.stop();

          SoundMixer.stopAll();

           

          var toys:boysToys =  new boysToys();

          addChild(toys);

          lastAdded_mc=toys;

          toys.x = 34;

          toys.y = 38;

          //trace("button clicked");

          }

           

          //If the fifth button is clicked auto replaces Random Movie

          buttonAuto.addEventListener(MouseEvent.CLICK, button5Clicked);

           

          function button5Clicked(event:MouseEvent):void {

           

          removeChild:(lastAdded_mc);

          lastAdded_mc.stop();

          SoundMixer.stopAll();

           

          var auto:automotive =  new automotive();

          addChild(auto);

          lastAdded_mc=auto;

          auto.x = 34;

          auto.y = 38;

          //trace("button clicked");

          }

           

          //If the sixth button is clicked troops replaces Random Movie

          buttonTroops.addEventListener(MouseEvent.CLICK, button6Clicked);

           

          function button6Clicked(event:MouseEvent):void {

           

          removeChild:(lastAdded_mc);

          lastAdded_mc.stop();

          SoundMixer.stopAll();

           

          var troops:troopTradition =  new troopTradition();

          addChild(troops);

          lastAdded_mc=troops;

          troops.x = 34;

          troops.y = 38;

          //trace("button clicked");

          }

           

          var myFrame:emptyMC = new emptyMC();

          addChild(myFrame);

          myFrame.x = 33;

          myFrame.y = 37;

           

           

          • 2. Re: Help Please! Movies play in background!
            EGBAR.Mary Community Member

            Thank you for the response and code, but there is still something playing in the main window. I think it's the random movie.

            • 3. Re: Help Please! Movies play in background!
              kglad CommunityMVP

              i included code to remove and stop the randomly selected movieclip.   replace your code with the code copied from my suggestion and retest.

              • 4. Re: Help Please! Movies play in background!
                EGBAR.Mary Community Member

                I copied and pasted your entire code and saved it as a new document. Then I maded the newly mc at a y=30 just to see if there is anything in the background. It seems that the last added mc isn't unloading. I am so thankful that you are trying to help. Am I missing something?

                • 5. Re: Help Please! Movies play in background!
                  EGBAR.Mary Community Member

                  This worked in the function instead of removeChild

                   

                  if(mc){

                  if (mc.stage)  {

                  removeChild(mc);

                  }

                  }

                   

                  if(lastAdded_mc){

                  if (lastAdded_mc.stage)  {

                  removeChild(lastAdded_mc);

                  }

                  }

                   

                  I changed each coordinates to extremes and each time the movie where removed when button was clicked. Thank you so much for your help.

                  • 6. Re: Help Please! Movies play in background!
                    kglad CommunityMVP

                    you're welcome.

                     

                    p.s.  please mark helpful/correct responses, if there are any.

                    • 7. Re: Help Please! Movies play in background!
                      EGBAR.Mary Community Member

                      //If the first button is clicked ThreePrinciples is replaces Random Movie
                      buttonPrinciples.addEventListener(MouseEvent.CLICK, button1Clicked);

                       

                      function button1Clicked(event:MouseEvent):void
                      {

                       


                          if (mc)
                          {
                              if (mc.stage)
                              {
                                  removeChild(mc);
                              }
                          }

                       

                          if (lastAdded_mc)
                          {
                              if (lastAdded_mc.stage)
                              {
                                  removeChild(lastAdded_mc);
                              }
                          }
                          //lastAdded_mc.stop();

                       

                          SoundMixer.stopAll();

                       

                          var bruce:threePrinciples = new threePrinciples();
                          addChild(bruce);
                          lastAdded_mc = bruce;
                          bruce.x = 34;
                          bruce.y = 38;
                          //trace("button clicked");
                      }

                       

                      Thank you again for your help!

                      • 8. Re: Help Please! Movies play in background!
                        kglad CommunityMVP

                        you're welcome.