8 Replies Latest reply on Sep 16, 2010 1:41 PM by TheBrody

    attachMovie problem - Need help

    TheBrody

      I'm trying to make a statusbar thing, each time you press the button, it attaches a new Movieclip. But it will only attach 1, then that 1 just moves down each time I press it.

       

      function StatusTextUpdate() {
          AmountVisible++;
          root.menus.attachMovie("StatusUpdate", "StatusUpdate_"+AmountVisible, 1, {_x:-330.00,_y:20 * (AmountVisible) + (-500) });
      }

       

      I want it so it adds another 1 each time its pressed. Could someone show me how I can do this?

        • 1. Re: attachMovie problem - Need help
          kglad Adobe Community Professional & MVP

          you need to assign a different depth to each movieclip otherwise they're replacing one another.  at most, there can be one movieclip per depth:

           


           

          function StatusTextUpdate() {
              AmountVisible++;
              root.menus.attachMovie("StatusUpdate", "StatusUpdate_"+AmountVisible, AmountVisible, {_x:-330.00,_y:20 * (AmountVisible) + (-500) });
          }

           

           

          • 2. Re: attachMovie problem - Need help
            TheBrody Level 1

            Inside the Movieclip, I have a text field. I'm trying to set the text to it, but it will not work.

             

            function StatusTextUpdate() {
                AmountVisible++;


                _root.menus.attachMovie("StatusUpdate", "StatusUpdate_"+AmountVisible, AmountVisible, {_x:-330.00,_y:25*(AmountVisible)+(-530.00)});


                _root.menus.StatusUpdate_[AmountVisible].StatusTxt.text = "Your motto has been updated.";
            }

             

             

            What is wrong with this?

            • 3. Re: attachMovie problem - Need help
              Ned Murphy Adobe Community Professional & MVP

              Try:

               

              _root.menus["StatusUpdate_"+AmountVisible].StatusTxt.text = "Your motto has been updated.";

              1 person found this helpful
              • 4. Re: attachMovie problem - Need help
                TheBrody Level 1

                Thanks that worked. Now, how can I make it so it only stays up for 7 seconds, then it removes the movieclip and the AmountVisible goes down?

                 

                function StatusTextUpdate() {
                    AmountVisible++;
                    _root.menus.attachMovie("StatusUpdate", "StatusUpdate_"+AmountVisible, AmountVisible, {_x:-330.00,_y:25*(AmountVisible)+(-530.00)});
                    _root.menus["StatusUpdate_"+AmountVisible].StatusTxt.text = "Your motto has been updated.";
                }

                 

                There is my code so far.

                • 5. Re: attachMovie problem - Need help
                  Ned Murphy Adobe Community Professional & MVP

                  See what you can reason out after looking into the setTimeout function and the MovieClip.removeMovieClip() method.

                  • 6. Re: attachMovie problem - Need help
                    TheBrody Level 1

                    I was able to make them remove, but it glitches if I press my button to many times.

                     

                    function CountTheStatus() {   
                            var bDuration:Number = 7000;
                            var bId:Number = setTimeout(Delegate.create(this, FadeTheStatus), bDuration);
                    }
                       
                    function FadeTheStatus():Void {
                        _root.menus["StatusUpdate_" + AmountVisible].gotoAndPlay("FadeOut");
                    }

                     

                    function DeleteTheStatus(){
                        _root.menus["StatusUpdate_" + AmountVisible].removeMovieClip();
                        AmountVisible--;
                    }

                     

                    It all works, except if theres more then 1 at a time. How can I fix this problem?

                    • 7. Re: attachMovie problem - Need help
                      Ned Murphy Adobe Community Professional & MVP

                      You are relying on the value of AmountVisible with that approach, which can only point to the most recent one added.  I would try to set it up so that the setTimeout is called within the StatusTextUpdate function, and use the new instance as an argument that you pass to the function in the setTimeout call so that the one associated with the setTimeout is going to be processed.

                       

                      You will probably find you end up wth a problem decrementing the AmountVisible value since you use it to name the instances.  If you name one using the value, then remove an earlier one and decrement the value you can end up with more than one having the same instance name.  So if you need to keep track of how many are present, then you may want to have a separate variable for that purpose and just let the AmountVisible continue to increment.

                      • 8. Re: attachMovie problem - Need help
                        TheBrody Level 1

                        How could I get that to work?