7 Replies Latest reply on Jun 12, 2011 2:10 PM by kglad

    Problem with duplicatemovieclip

    andib311

      Hi there, can anybody please advise where I've gone wrong with the code below. It is applied to a single (unnamed) instance of an mc in the center of the stage. The mc moves slowly towards the left and the desired effect is that upon clicking it, a duplicate will appear, which in turn when clicked will cause a duplicate to appear and so on.

      With the code below, I am able to move the mc slowly to the left and duplicate it at x position 10 (and foward its own timeline to frame "hit"), but its duplicate will complete no actions at all when clicked.

       

       

      onClipEvent (load) {
          xspeed = 0;
          yspeed = 0;
          movement = 0.5;

       


      // Create the Movement

       


          this.onEnterFrame = function() {

       

              if (startup=true and !alive) {
                  xspeed -= movement;
                  alive = true;

       

              }

       


              forecast_x = this._x+xspeed;
                 
              this._x = forecast_x;

       

          }

       

          this.onRelease = function() {
         
              this.onEnterFrame = function() {

       

                  if (this._currentframe=="1") {
                      this.gotoAndStop("hit");
                      yspeed =0;
                     
                      delete this.onEnterFrame;
                     
                         
                   }
                 
              }

       

      this.duplicateMovieClip(this.getNextHighestDepth());

      this._x =10;

          }

      }

       

      Any help would be greatly appreciated. Thanks

        • 1. Re: Problem with duplicatemovieclip
          kglad Adobe Community Professional & MVP

          what's startup?  what's alive?  what's forcast_x?  is yspeed ever used?

          • 2. Re: Problem with duplicatemovieclip
            andib311 Level 1

            These are variables that will be called once the code is more developed.
            My reasoning was that until the basic (and highly important) duplicate function was working there was no point even bothering with the next stages. This is the first hurdle.

            These variables are redundant at this time and have no actions elsewhere - you are looking at the code in its  entirety.

            • 3. Re: Problem with duplicatemovieclip
              kglad Adobe Community Professional & MVP

              1st, remove all code from that movieclip:  no code should be attached to objects.

              2nd, assign your movieclip an instance name, eg mc.  you can then use:

               

              function init(mc:MovieClip):Void {

                  mc.xspeed = 0;
                  mc.yspeed = 0;
                  mc.movement = 0.5;

              mc.startup=?;

              mc.alive=?

              }

               

              function moveF(mc:MovieClip):Void{

                  mc.onEnterFrame = function() {

                      if (this.startup and !this.alive) {
                          this.xspeed -= this.movement;
                          this.alive = true;

                      }
                      this.forecast_x = this._x+this.xspeed;
                      this._x = this.forecast_x;

                  }

              }

               

              function onReleaseF(mc:MovieClip):Void{

                  mc.onRelease = function() {
                      this.onEnterFrame = function() {

                          if (this._currentframe=="1") {
                              this.gotoAndStop("hit");
                              this.yspeed =0;
                              delete this.onEnterFrame;
                           }
                      }

                   var n:Number=this._parent.getNextHighestDepth();

                   var dup_mc:MovieClip=this._parent.duplicateMovieClip("mc_"+n,n);

              initF(dup_mc);

              moveF(dup_mc);

              releaseF(dup_mc);

                   this._x =10;

                  }

              }

               

               

              • 4. Re: Problem with duplicatemovieclip
                andib311 Level 1

                That doesn't appear to work, even when I take out the lines that aren't currently being called.

                 

                There is no initial movement or subsequent duplication.

                • 5. Re: Problem with duplicatemovieclip
                  kglad Adobe Community Professional & MVP

                  did you pass your movieclip to init()?

                  1 person found this helpful
                  • 6. Re: Problem with duplicatemovieclip
                    andib311 Level 1

                    I'm sorry, I'm not sure I follow. I took the code you last offered, placed it in the timeline as opposed to the mc, named the mc instance "mc" for the time being and removed the code from the mc.

                     

                    I'm possibly missing another step?

                    • 7. Re: Problem with duplicatemovieclip
                      kglad Adobe Community Professional & MVP

                      try:

                       

                      init(mc);

                       

                      function init(mc:MovieClip):Void {

                          mc.xspeed = 0;
                          mc.yspeed = 0;
                          mc.movement = 0.5;

                      mc.startup=?;

                      mc.alive=?

                      }

                       

                      function moveF(mc:MovieClip):Void{

                          mc.onEnterFrame = function() {

                              if (this.startup and !this.alive) {
                                  this.xspeed -= this.movement;
                                  this.alive = true;

                              }
                              this.forecast_x = this._x+this.xspeed;
                              this._x = this.forecast_x;

                          }

                      }

                       

                      function onReleaseF(mc:MovieClip):Void{

                          mc.onRelease = function() {
                              this.onEnterFrame = function() {

                                  if (this._currentframe=="1") {
                                      this.gotoAndStop("hit");
                                      this.yspeed =0;
                                      delete this.onEnterFrame;
                                   }
                              }

                           var n:Number=this._parent.getNextHighestDepth();

                           var dup_mc:MovieClip=this._parent.duplicateMovieClip("mc_"+n,n);

                      initF(dup_mc);

                      moveF(dup_mc);

                      releaseF(dup_mc);

                           this._x =10;

                          }

                      }

                       

                       

                      1 person found this helpful