2 Replies Latest reply on May 20, 2015 7:08 PM by Ned Murphy

    Can't go to next frame and I got this Error #1009: Cannot access a property or method of a null object reference

    azkianury

      I'm making a quiz game and when I press the play button on frame 1, it will shuffle and go to random next frame. So I wrote this code on frame 1:


      stop();

      function shuffle(arr:Array):void {
       
      var len:Number = arr.length - 1;
       
      for (var i:Number = len; i >= 0; i--) {
        
      var p:Number = Math.floor(Math.random() * (i + 1));
        
      var t:Object = arr[i];
        arr
      [i] = arr[p];
        arr
      [p] = t;
       
      }
      }

      var labels:Array = ["question1", "question2", "question3"];
      shuffle
      (labels);
      var nomerLabel:Number = 0;

      function gotoNextLabel():void {
       
      if (nomerLabel < labels.length) {
        gotoAndPlay
      (labels[nomerLabel]);
        nomerLabel
      ++;
       
      } else {
      nomerLabel
      = 0;
      shuffle
      (labels);  //<-if you want to re-randomize labels. otherwise, omit this line
      gotoNextLabel
      ();
       
      }
      }

      PlayButton.addEventListener(MouseEvent.MOUSE_DOWN, clickbutton);
      function clickbutton(e:MouseEvent):void
      {
        gotoNextLabel
      ();
      }


      and I wrote this code on all the next frames, when the user clicks the right answer, it will call the gotoNextLabel() function to shuffle frames again:

      stop();

      next1.addEventListener(MouseEvent.MOUSE_DOWN, clickbutton1);

      function clickbutton1(e:MouseEvent):void

      {

          gotoNextLabel();

      }

       

      And I always get an Error #1009: Cannot access a property or method of a null object reference. Did I miss something there? How do I fix it? Thank you.