3 Replies Latest reply: Nov 5, 2011 8:53 AM by kglad RSS

    Simple AS3 to AS2 translation (display list manipulation)

    Peter Celuch Community Member

      Can anybody translate this piece of code to AS2? Don't ask why

      Thanks.

       

      var pictureIndex:int = 0;
      var pictures:Array = [];
       
      mc_animation.gotoAndStop(1);
      mc_animation.visible = false;
      mc_animation.addEventListener(Event.COMPLETE, animationCompleteHandler);
       
      loadPictures();
       
       
      function loadPictures():void {
           // you should load pictures and store them in the pictures Array
           // when you're done loading pictures, call loadPicturesComplete()
      }
       
      function loadPicturesComplete():void {
           showNextPicture();
           mc_animation.visible = true;
      }
       
      function clearAnimationHolder():void {
          while(mc_animation.mc_holder.numChildren > 0) {
              mc_animation.mc_holder.removeChildAt(0);
          }
      }
       
      function showNextPicture():void {
          if(pictureIndex < pictures.length) {
              clearAnimationHolder();
              mc_animation.mc_holder.addChild(pictures[pictureIndex]);
              mc_animation.gotoAndPlay(1);
          }
          else {
              trace("DONE SHOWING PICTURES");
          }
      }
       
      function animationCompleteHandler(event:Event):void {
           // if you want co cycle through images in infinite loop, try this instead of the next line: pictureIndex = (pictureIndex + 1) % pictures.length;
          pictureIndex++;
       
          showNextPicture();
      }