38 Replies Latest reply on Sep 22, 2017 12:32 PM by kglad

    Nested loop not working

    shasimo Level 1

      Hi
      I'm new to Animate and createJS, and I'm trying to learn the syntax, but I'm stuck with this code, where my loop wont loop, meaning that the outer loop stops after the first iteration.

       

      var letters = ["M_container", "O1_container", "T_container", "I_container", "O2_container", "N_container"]
      // Pause events
      root.pauseBtn.addEventListener("click", pauseAll.bind(this));
      function pauseAll() {    
          var j;
          var i;
          var containermc;
          for (j = 0; j < letters.length; j++) {
              containermc = letters[j];
              for (i = root[containermc].numChildren - 1; i >= 0; i--) {
                  var mc = root[containermc].getChildAt(i);    
                  mc.stop();
              }
          }
      }
      

       

      So all instances running in the first containermc "M_container" stops as intended, but then nothing else happens.

       

      Also, I'm getting a console error from line 12 ( mc.stop();) , saying that it's not a function even though it works.


      I hope someone can help me

       

      P.s. Where can I find some guides for rewriting actionscript syntax to javascript/createJS?
      createjs.com is fine for learning some things, but I'm an unexperienced coder, so I need some really basic stuff - maybe I should learn Javascript from the bottom?
      Is native Javascript working in Animate? Sorry if it's a dumb question