3 Replies Latest reply on Nov 13, 2007 7:35 AM by gigisfarleaza

    Random value not equal to

    BigdaddyVELTRI
      I'm building a script and I want to load 4 Movies into different targets on my stage but I don't want the same one to show up twice.

      Here's what I have so far. Which works find randomly but sometime shows the same movie loaded, which I don't want to happen.

      x = 0;
      while (x == 0) {
      x = random(3);
      }
      file1 = "sm_movie"+x+".swf";
      loadMovie(file1, thumb1);

      y = 0;
      while (y == 0) {
      y = random(3); //notice i have 11 here...
      }
      file2 = "sm_movie"+y+".swf";
      loadMovie(file2, thumb2);


      I tried using x != y and y != x
        • 1. Re: Random value not equal to
          kglad Adobe Community Professional & MVP
          place your file names in an array, apply the shuffle method to your array and then load your movies using the shuffled array:

          • 2. Random value not equal to
            clbeech Level 3
            You could use an array, and remove an element on each load using splice, but once the array is empty, you'd need to re-establish it again so use two, one that remains and one that is a copy.

            EDIT: here we go again, crap! ... sorry kg lol!!!
            • 3. Re: Random value not equal to
              gigisfarleaza Level 1
              you create an array to pot the movies that you played in
              you can create a recursive function

              var arr:Array=new Array()
              function genRandom(){
              var f:Boolean=false
              x=random(3)
              for(var i=0;i<arr.length;i++){
              if(x=arr ){
              f=true
              }
              }
              if(f){
              f=fasle
              ganRandom()
              }else{
              arr.push(x)
              //put your code to load this movie
              }
              }

              the function generate a random number, verifies if the number is or not in the array, if the number is found in the array it generates another one...