2 Replies Latest reply on Jan 2, 2011 11:43 AM by Andrei1

    Ugly Switch Statement

    beno12345 Level 1

      Hi;

      I have this ugly code:

       

                  var i:Number = new Number(0);

                  while (i > 6)
                  {
                      switch (i)
                      {
                          case (0):
                          container = container0;
                          break;
                          case (1):
                          container = container1;
                          break;
                          case (2):
                          container = container2;
                          break;
                          case (3):
                          container = container3;
                          break;
                          case (4):
                          container = container4;
                          break;
                          case (5):
                          container = container5;
                          break;
                      }
                      container.addChild(img);
                      i++;
                  }

       

      All of these containers are then added into a parent container with their x and y coordinates set separately so that they don't overlap. Is it possible to set those coordinates to either the img or the specific container (i.e., container2)? I tried the following:

       

                  /*
                  if (img.parent)
                  {
                      img.parent.removeChild(img);
                  }
                  */
                  i = 0;
                  while (i < _numOfSlides)
                  {
                      img.myArray = [imagesArray[_const*_numOfSlides+_mod+i], "index.py", _w, _h, ((_w+spacer)*j)+_x+600, _y];
                      container.addChild(img);
                      img.x = _w*i
      //                parent_container.addChild(container);
                      trace(i);
                      ++i;
                  }


      uncommenting the commented out portions, but to no avail. The trace traces but no images print to screen. The ugly code does in fact work. Please advise.

      TIA,

      beno