8 Replies Latest reply on Jun 19, 2006 5:03 AM by Teshla

    Problems with instances

    Teshla
      I need a same action to occur for few movie clips. For example i have instances: P1 P2 P3 P4.
      I tried:
      Calling every one of them by one name.
      Writing P[1,2,3,4]
      Writing G = "P" +[1,2,3,4]

      Can anyone help me?
        • 1. Re: Problems with instances
          2m Level 2
          for (var i = 0; i < 5; i++){
          ParentMoviclipName["P"+i].doSomethingFunction();
          }

          Would do the trick.

          It's called a loop.
          • 2. Re: Problems with instances
            Teshla Level 1
            I have one more question, does this loop take multiple frames or only one?
            • 3. Re: Problems with instances
              2m Level 2
              The loop executes in the one frame it is placed on. The comands issued within (e. g. play()) can effect any number of frames on that timeline or any other they are connected with.

              If one of your movie clip instances isn't present at the frame where your loop is placed, no action on that clip can happen.
              • 4. Re: Problems with instances
                Teshla Level 1
                I didn't mean frames that are in timeline. For example:
                onClipEvent (enterFrame) {
                something._x + = 20
                }



                So it will take 2 frames to move it by 40, 3 frames to move it by 60 (and so on) even if nothing is playing in the timeline. Thats what about i was talking (maybe this thing has other name that i do not know).
                By the way i cant make anything with this loop, I guess i asked wrong. I dont need some sort of function to occur, I need that all movie clips with those instances would change their position.
                • 5. Re: Problems with instances
                  2m Level 2
                  So you have an instruction that makes your clip move over time. that instructin works (looks like at least). Right?

                  You could put that instruction to any number of clips without problems. Right?

                  So what you want is puting said instruction on more than one clip without having to do son one by one manually? Right?

                  A loop would still do that. INstead of "doSomethingFunction()" you just would write:

                  for (var i = 0; i < 5; i++){
                  ParentMoviclipName["P"+i].onEnterFrame = function (){
                  this._x +=20;
                  }
                  }
                  • 6. Re: Problems with instances
                    Teshla Level 1
                    I have a game where screen moves together with character (that means that all the obstances, enemies, floor and so on move to direction opposite of the one you pressed). And I want to save myself a lot of time. Because this loop that you teached me about will let me move all the pieces with writing one line instead of writingn 3 lines for each.
                    This is how my script looks now:

                    onClipEvent (enterFrame) {
                    if (Key.isDown (Key.RIGHT)){
                    _root.Floor1._x -= speed;
                    _root.Floor2._x -= speed;
                    }
                    }


                    The place i underlined shows Where I need to insert the loop cuz there will be many more Floor pieces.

                    P. S. Most of the script u wrote me I understand, but why do I need Parent Movie Clip Name?
                    • 7. Re: Problems with instances
                      Teshla Level 1
                      Sorry for this but i really need the answer.
                      • 8. Re: Problems with instances
                        Teshla Level 1
                        Thanks for the help, script was slightly diffirent but thanks to you i learne <<<The Loop>>>.