title: Flash AS3 - how to randomize each frame while play
body: <p>I have some quiz level 1 in frame 2-11 and frame 12 is the result of quiz, and quiz level 2 in frame 13-22 with result in frame 23..</p>
  
  <p>i want to randomize a quiz between 2-11 and randomize a quiz in frame 13-22,</p>
  
  <p><strong>Example :</strong></p>
  
  <ol>
  <li>1st quiz is frame 3</li>
  <li>2nd quiz is frame 6</li>
  <li>3rd quiz is frame 2</li>
  <li>(... ...)</li>
  <li>(n)th ... ... ...(last frame that not yet showing)</li>
  </ol>
  
  <p>I'm using this code in frame 1 :</p>
  
  <pre><code>stop();
  autom.play();
  soal = 1;
  var pic:Number=11;
  var randomFrame:Number = Math.ceil(Math.random()*pic);
  trace(randomFrame);
  gotoAndStop(randomFrame);
  nextFrame();
  </code></pre>
  
  <p>but the flash randomize just first time</p>
  
  <p>i want to know if there is a way to make it possible to make the flash running well like what i want in <strong>Example</strong>???</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p><code>full code of frame 1</code></p>
  
  <pre><code>var kunci:String,
  jawaban:String,
  dikunci:String,
  soal:int,
  betul:int,
  salah:int,
  hati:int=0,
  nilai:int,
  mcres:mcrespon = new mcrespon();
  mcres.x = 20;
  mcres.y = 40;
  mcres.scaleX = 3;
  mcres.scaleY = 3;
  
  tbhome.addEventListener(MouseEvent.MOUSE_UP,clikmenu);
  tbmulai.addEventListener(MouseEvent.CLICK,cliklanjut);
  function cliklanjut(event:MouseEvent):void
  {
      stop();
      autom.play();
      soal = 1;
      betul = 0;
      salah = 0;
      nilai = 0;6;
      var pic:Number=22;
      var randomFrame:Number = Math.ceil(Math.random()*pic);
      trace(randomFrame);
      gotoAndStop(randomFrame);
      nextFrame();
      /*stop();
      autom.play();
      soal = 1;
      var pic:Number=11;
      var randomFrame:Number = Math.ceil(Math.random()*pic);
      trace(randomFrame);
      gotoAndStop(randomFrame);
      nextFrame();*/
  }
  function clika(event:MouseEvent):void
  {
      autom.play();
      jawaban = "a";
      cocokan();
  }
  function clikb(event:MouseEvent):void
  {
      autom.play();
      jawaban = "b";
      cocokan();
  }
  function clikc(event:MouseEvent):void
  {
      autom.play();
      jawaban = "c";
      cocokan();
  }
  function clikd(event:MouseEvent):void
  {
      autom.play();
      jawaban = "d";
      cocokan();
  }
  function cocokan()
  {
      addChild(mcres);
      if (jawaban == kunci)
      {
          mcres.gotoAndPlay(2);
          setTimeout(lanjutbenar,0);
      }
      else
      {
          mcres.gotoAndPlay(16);
          setTimeout(lanjutsalah,0);
      }
  }
  function copot()
  {
      removeChild(mcres);
  }
  function lanjutbenar()
  {
      betul +=  1;
      soal +=  1;
      copot();
      nextFrame();
  }
  function lanjutsalah()
  {
      salah +=  1;
      hati +=  1;
      mchati.nextFrame();
      copot();
      if (hati&gt;=3)
      {
          gotoAndStop("gameover");
      }
      else
      {
          soal +=  1;
          nextFrame();
      }
  }
  function clikulang(event:MouseEvent):void
  {
      autom.play();
      soal = 1;
      betul = 0;
      salah = 0;
      nilai = 0;
      hati = 0;
      gotoAndStop(1);
  }
  function kuncinya(sikunci:String)
  {
      soalnya.text = "Soal no " + soal.toString() + "/20";
      pila.addEventListener(MouseEvent.CLICK,clika);
      pilb.addEventListener(MouseEvent.CLICK,clikb);
      pilc.addEventListener(MouseEvent.CLICK,clikc);
      pild.addEventListener(MouseEvent.CLICK,clikd);
      kunci = sikunci;
  }
  
  function diresumequis(batasbagus:int,komen1:String,komen2:String,komen3:String)
  {
      stop();
      tbulang.addEventListener(MouseEvent.CLICK,clikulang);
      tbnextlevel.addEventListener(MouseEvent.CLICK,cliklanjut);
      betulnya.text = "Benar = " + betul.toString();
      salahnya.text = "Salah = " + salah.toString();
      nilai = betul / 10 * 100;
      nilainya.text = "Nilai = " + nilai.toString();
  
      if (nilai == 100)
      {
          komentar.text = komen1;
      }
      else
      {
          if (nilai&gt;=batasbagus)
          {
              komentar.text = komen2;
          }
          else
          {
              komentar.text = komen3;
          }
      }
  }
  </code></pre>
  
  <p><code>in frame 2 till 11 are a same code like this :</code></p>
  
  <pre><code>kuncinya("a") // the correct answer of a question;  
  </code></pre>