4 Replies Latest reply: May 23, 2013 11:47 PM by moccamaximum RSS

    Hello, I am trying to write a small game i

    cabaka11 Community Member

      Hello,

       

      I am trying to write a small game in which the instance (theman) is supposed to touch three green balls (the instance names of which are green1, green2. green3) consecutively.

       

      However, I cannot get the code in the correct format. I used "green1", "green2", "green3" as framelabels. While the "green1" label is working the second one ("green2") is not working at all. I am getting the "HittestObject must be non-null error # 2007" all the time with the second function (tocuhing2).

       

      What I do not understand is that it is exactly the same code I am using above.

       

      Could someone please let me know what is wrong with the code below?

       

       

      var points:Number = 0;

       

      if (points >= 5) {

          trace ("Done!")

      }

       

      stage.addEventListener(Event.ENTER_FRAME, touching1);

      function touching1(e:Event)

      {

          if (theman.hitTestObject(green1) == true)

          {

              green1.alpha = 0;

              points = 1;

              trace(points);

              gotoAndPlay("green2");

          }

      }

       

      stage.addEventListener(Event.ENTER_FRAME, touching2);

      function touching2(e:Event){

          if (theman.hitTestObject(green2) == true) {

              green2.alpha = 0;

              points = 2;

              trace (points);

              gotoAndPlay("green3");

          }

       

      Best,

      Cagri Kasap

        • 1. Re: Hello, I am trying to write a small game i
          moccamaximum Community Member

          HittestObject must be non-null error

          If your 3 objects are only living in one frame of your timeline

          the enter_frame functions will not find the other two objects.

           

          alter your function as follows

           

          stage.addEventListener(Event.ENTER_FRAME, touching);

          function touching(e:Event){

          if(this.currentFrame == 1){

              if (theman.hitTestObject(green1) == true) {

                  green1.alpha = 0;

                  points = 2;

                  trace (points);

                  gotoAndPlay("green2");

              }

          }

          else if (this.currentFrame == 2){

            //insert your touching2 functions code

          }

           

          else if (this.currentFrame == 3){

          //insert your touching3 functions code

          }

          }

          • 2. Re: Hello, I am trying to write a small game i
            cabaka11 Community Member

            Hello,

             

            Thank you very much for your response. However, I could not make it work the way you suggested either. I guess the reason is because my three objects are not in the same frame. The first green ball is located at Frame 1. The second green ball is located at Frame 3 and the third green ball is located at Frame 6.

             

            And they all have frame labels as ("green1"), ("green2"), ("green3") seperately. I assume this is why you are code does not work either.

             

            Would you have any other suggestions for me?

             

            Thank you very much for your time and consideration.

             

            Best,

            Cagri Kasap

            • 3. Re: Hello, I am trying to write a small game i
              Nabren Community Member

              You could use if (this.currentFrameLabel == "green1"), if (this.currentFrameLabel == "green2") or if (this.currentFrameLabel == "green3") for your frame checks in that case.

              • 4. Re: Hello, I am trying to write a small game i
                moccamaximum Community Member

                this.currentFrameLabel should be this.currentLabel, otherwise Nabrens advice is sound