5 Replies Latest reply on Nov 17, 2010 7:10 AM by xxxheeroxxx

    generate non duplicating random number from a range of values

    xxxheeroxxx Level 1

      Good day people,

       

      I need help again. I want to animate an image inside a movieclip with frame label animate1, animate2, animate3 and animate4.

      I did manage to generate random numbers but my concern is that I want my animation will not animate same image twice, below is my code.

       

      ==== code in main time line ====

      function randRange(min:Number, max:Number):Number {
          // Generate a number between and including min – max
          var randomNum:Number = Math.floor(Math.random()*(max-min))+min;
          return randomNum;
      }


      //build array to hold frame label names
      var frameArray:Array = new Array();
          frameArray[0] = "animate1";
          frameArray[1] = "animate2";
          frameArray[2] = "animate3";
          frameArray[3] = "animate4";
         
      // Get random number created
      var n:Number = randRange(0, frameArray.length);


      trace("n: " + n);


      // gotoAndStop Frame label name    
      this.img_ani.gotoAndStop(frameArray[n]);


      trace("frameArray: " + frameArray[n])

       

      ==== code and frame label inside a movie clip with 4 frames containing different images ===

      as layer: stop();

      frame label: animate1, animate2, animate3, animate4

       

       

      Any help is greatly appreciated. Thanks in advance.