9 Replies Latest reply on Dec 21, 2006 1:22 AM by MatMaar

    onEnterFrame - duplicateMC

    MatMaar


      I have duplicate a mc several times. Now I want to attach to every duplicated mc a onEnterFrame function.
      What I'm looking for is a shorten method for:

      _root.MC0.onEnterframe = function;
      _root.MC1.onEnterframe = function;
      _root.MC2.onEnterframe = function;
      _root.MC3.onEnterframe = function;
      _root.MC4.onEnterframe = function;
      _root.MC5.onEnterframe = function;
      etc etc etc (this all works btw)


      to something like this
      for (i=0; i < gewenstaantal; i++){
      _root."MC"+i.onEnterframe = function;
      }
      THIS DOESN'T work

      Hopefulley somebody can help
        • 1. onEnterFrame - duplicateMC
          .:}x-=V!P=-x{:. Level 3
          like this?
          • 2. Re: onEnterFrame - duplicateMC
            Level 7
            > like this?
            >
            > for (i=0; i<gewenstaantal; i++) {
            > _root["MC"+i].onEnterFrame = functionName;
            > }

            Bingo! .:}x-=V!P=-x{:. nailed it. The big difference here is the
            appearance of the array access operator (the square brackets, []). Either
            the array access operator or the eval() function -- one or the other -- is
            required in this situation. Without either one, the reference created
            (_root."MC"+i in the original example) is a String, not a MovieClip
            reference, and Strings don't have an onEnterFrame event.

            See this article for additional detail.

            http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically


            David Stiller
            Adobe Community Expert
            Dev blog, http://www.quip.net/blog/
            "Luck is the residue of good design."


            • 3. Re: onEnterFrame - duplicateMC
              MatMaar Level 1
              Sorry my mistake

              The names of the duplicatedMC's are stored in a array, and I'm starting of from the array

              here's my code I now have.


              function setNewImagePosition(){
              speed = 4;
              for(i=0; i<_root.myArray12Length; i++){
              _root.myArray12 .onEnterFrame = function(){
              myWidth = this.width;
              targetX = (80+myWidth+(i*20))
              this._x += (targetX-this._x)/speed;
              }
              }
              }
              • 4. Re: onEnterFrame - duplicateMC
                .:}x-=V!P=-x{:. Level 3
                thanks David S. I can help most people but I am bad at technical explanations, its good to get it working but the other half is understanding why it works. also thanks for the explanation on the other post with the "!" question.
                • 5. Re: onEnterFrame - duplicateMC
                  MatMaar Level 1
                  Can I remember you folks, this question wasn't answered yet?

                  Please keep in mind that the name of the duplicated MC comes out of an array....
                  • 6. Re: onEnterFrame - duplicateMC
                    Devendran Level 1
                    HI
                    You missed the Array index to get the MovieClip from and array.
                    myArray will send you all the Values as String, But myArray[0] will return the value or myArray value at 0th index
                    • 7. Re: onEnterFrame - duplicateMC
                      MatMaar Level 1
                      I did tests and tests and....
                      but there's something wrong and I don't know what.

                      here's my script again. A bit modified, but for start It won't f.Ex trace the Xpostiton of the dup MC. So it definetly won't make the onEnterFreame functions...
                      Please help

                      function setNewImagePosition(){
                      for(i=0; i<_root.myArray12Length; i++){
                      speed = 4;
                      whichNumber = _root.myArray12 ;
                      whichNumber = whichNumber.substr(1,1);
                      _root["whichMC"+i] = "ImageMenuItem" + whichNumber;
                      trace("whichMC: " + _root["whichMC"+i]);
                      myX = _root["whichMC"+i]._x;
                      trace("myX : " + myX );

                      myWidth = _root["whichMC"+i]._width;
                      trace("myWidth : " + myWidth );

                      _root["targetX"+i] = (80+myWidth+(i*20));

                      _root["whichMC"+i].onEnterFrame = function(){
                      this._x += (_root["targetX"+i]-this._x)/speed;
                      }
                      }
                      }
                      • 8. onEnterFrame - duplicateMC
                        Devendran Level 1
                        Hi,
                        _root.myArray12Length // U can't use in this Format.... to get length of an array use -> _root.myArray12.length
                        u missed "." and "Length" should be "length";

                        And another one thing.
                        whichNumber = _root.myArray12; // this will return Whole Content of an array as comma seperated value. if u wish to get an particular indexed value u have to use whichNumber = _root.myArray12

                        I don't know what you are storing inside the myArray12;
                        now Try.... if you stored the movie name inside the array, then no need to get index and againg forming the name of the mc. you can directly use the stored name...


                        • 9. Re: onEnterFrame - duplicateMC
                          MatMaar Level 1
                          _root.myArray12Length is just the variabel I made. So no need for the . before "length"

                          What I strored in the array f.ex
                          [01, 02, 03, 04,]

                          So I need the last number so that's why the Index to format eventualy f.ex , "ImageMenuItem1", "ImageMenuItem2", ....