7 Replies Latest reply on Jul 10, 2009 8:16 AM by Edcetseb

    Movie Clips

    Edcetseb

      Yes - I'm back. Apologies.

       

      In my movie clips, I already have functions such as the following:

       

      onClipEvent (enterFrame) {
          currentlocx = this._x;
          currentlocy = this._y;
          differencex = newX - currentlocx;
          differencey = newY- currentlocy;
          accelx = differencex/accelFactor;
          accely = differencey/accelFactor;
          this._x = this._x + accelx;
          this._y = this._y + accely;
          if (Math.round(this._y) == Math.round(newY) && Math.round(this._x) == Math.round(newX) ) {
              newX = Math.round(Math.random()*450);
              newY = Math.round(Math.random()*295);
              accelFactor = Math.ceil(Math.random()*1) + 2;
          }
      }
      onClipEvent (load) {
          newX = Math.round(Math.random()*450);
          newY = Math.round(Math.random()*295);
          accelFactor = Math.ceil(Math.random()*1) + 2;
      }

       

      How would I add other functions such as duplicateMovieClip(my_mc, "new_mc", 5);to the code. Where would I add them? I've tried adding them under (enterFrame) but my movieclip does not duplicate after every "x" seconds. In addition to this, I would like my movieclip to "disappear" whenever it is clicked. How can this be done? I would appreciate it if someone could help me to rewrite my code in such a way that it is usable. I've done my best and I'm kind of getting lost in the piles of Adobe Documentation

       

      Thank you!

        • 1. Re: Movie Clips
          kglad Adobe Community Professional & MVP

          what movieclip do you want to duplicate and when do you want to duplicate it?

           

          to remove your movieclip add an on(release), swapdephs to a removable depth (greater than 0) and use this.removeMovieClip()

          • 2. Re: Movie Clips
            Edcetseb Level 1

            The whole chunk of Actionscript mentioned above is actually on the movieclip itself. I would like to duplicate the movieclip after every 5 seconds. Also, I would like to remove the movieclip as soon as it is clicked.

             

            Would be grateful if you could show me where to insert the codes - because every time I try to insert the removeMovieClip it gives me a console error.

             

            Thanks again

            • 3. Re: Movie Clips
              kglad Adobe Community Professional & MVP

              you really shouldn't attach code to objects.  but given that's the way you're doing things:

               

               

               

              onClipEvent (enterFrame) {

              //and to do something every 5 seconds in this loop depends on your fps:

              loop++

              if(loop%(fps*5)==0){

              this.duplictateMovieClip("whatever_"+loop,loop);

              // you'll need to do something will these movieclips

              }


                  currentlocx = this._x;
                  currentlocy = this._y;
                  differencex = newX - currentlocx;
                  differencey = newY- currentlocy;
                  accelx = differencex/accelFactor;
                  accely = differencey/accelFactor;
                  this._x = this._x + accelx;
                  this._y = this._y + accely;
                  if (Math.round(this._y) == Math.round(newY) && Math.round(this._x) == Math.round(newX) ) {
                      newX = Math.round(Math.random()*450);
                      newY = Math.round(Math.random()*295);
                      accelFactor = Math.ceil(Math.random()*1) + 2;
                  }
              }
              onClipEvent (load) {

              loop=0;

                  newX = Math.round(Math.random()*450);
                  newY = Math.round(Math.random()*295);
                  accelFactor = Math.ceil(Math.random()*1) + 2;
              }

               

              on(release){
              this.swapDepths(this._parent.getNextHighestDepth());
              this.removeMovieClip();
              }

              • 4. Re: Movie Clips
                Edcetseb Level 1

                Thank you. The remove clip worked. Unfortunately, the duplicate code didn't work (yes I did rename the movieclip file). Nothing is being spawned on the screen. Could there be anything I am doing wrongly? (Only the duplicate code doesn't work - no script errors either).

                 

                The duplicateMovieClip code, when spelt correctly, doesn't work either. Any possible oversights on my end that I could have made an error?

                 

                Sorry, I'm kind of new to the developer side of Flash. Thanks for all your help

                • 5. Re: Movie Clips
                  kglad Adobe Community Professional & MVP

                  did you define fps?

                  • 6. Re: Movie Clips
                    Edcetseb Level 1

                    I've added the duplicate clip, the bonus movieclip as well as the timer in my game.

                     

                    Just one more thing before it's done and ready to go


                    When the clips are duplicated, they go above the cursor. Thus, it is impossible to click them to score any points. How do we make these duplicated movie clips go below the cursor? Right now, only the original one can be clicked, and acts normally (is under the cursor). The duplicated movieclips are above the cursor.

                     

                    Thanks for your help again.

                    • 7. Re: Movie Clips
                      Edcetseb Level 1

                      Could someone please help?