16 Replies Latest reply: Aug 18, 2012 7:24 AM by kglad RSS

    error #2007

    thunderxlight11111 Community Member

      hi , how are you all? i hope you fine...

       

      iam trying to make a game but when the object hit object to delete  another object i get these errors

       

      TypeError: Error #2007: Parameter hitTestObject must be non-null.

      at flash.display::DisplayObject/_hitTest()

      at flash.display::DisplayObject/hitTestObject()

      at MAIN/onEnterFrame()

       

      and here is the class

      (iam sure the problem from this class because i closed all the classes except 1 )

       

       

       

      package  {

      import flash.display.MovieClip;
      import flash.events.Event;


      public class MAIN extends MovieClip {
       
       
       
        public function MAIN() {
      addEventListener(Event.ADDED_TO_STAGE,onAddedToStage)  
      }


      public function onAddedToStage(event:Event):void
        {
      addEventListener(Event.ENTER_FRAME,onEnterFrame )
       
       
      }

        public function onEnterFrame (event:Event)
        {
        
          if (hero.hitTestObject(bat1) && (bat1) && (bat1.stage))
          {
           healthbar1.width -=1
           trace("HHH")
          }
          if (healthbar1.width >=  80 && healthbar1.width <=  100 ){
           zelda1.gotoAndPlay(1)
          }
          if (healthbar1.width >=  60 && healthbar1.width <=  80){
           zelda1.gotoAndPlay(2)
          }
          if (healthbar1.width >=  40 && healthbar1.width <=  60){
           zelda1.gotoAndPlay(3)
          }
          if (healthbar1.width >=  20 && healthbar1.width <=  40){
           zelda1.gotoAndPlay(4)
          }
          if (healthbar1.width >=  0 && healthbar1.width <=  20){
           zelda1.gotoAndPlay(5)
          }
          if (hero.hitTestObject(portal2)){
           var map2:MAP2 = new MAP2
           addChild(map2)
           if(map1.stage){
           removeChild(map1)
           }
           }
           if (hero.hitTestObject(portal3) && (portal3) && (portal3.stage) && (bat1)){

            var map4:BACKGROUND = new BACKGROUND();

            if(bat1){

           removeChild(bat1)

           bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);  // this doesn't need to be done unless you added a listener outside the Bat1 classs

           bat1 = null;

         removeChild(portal3)
         portal3 = null
        
         }
           }
          
        }


      }


      }

       

       

      i talked about this problem before in this discuss

      http://forums.adobe.com/message/4620620#4620620

       

      and all the project with the image here

      http://forums.adobe.com/message/4615780#4615780

       

      i tried alot to check with if statement the bat1 object but this error still.

       

      thank you

        • 1. Re: error #2007
          kglad CommunityMVP

          you're not following directions.  use the code i suggested.

           

          using

           

          if(hero.hitTestObject(bat1)&&bat1)

           

          is NOT the same as

           

          if(bat1){

          if(hero.hitTestObject(bat1))

          • 2. Re: error #2007
            thunderxlight11111 Community Member

            i did this

             

            if(bat1){

             

            if(hero.hitTestObject(portal2)){

             

                  var map4:BACKGROUND = new BACKGROUND();

             

             

             

                 removeChild(bat1)

             

                 bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);  // this doesn't need to be done unless you added a listener outside the Bat1 classs

             

                 bat1 = null;

             

            removeChild(portal3)

            portal3 = null

             

            but you know , after this code this if statement doesn,t work

            if(hero.hitTestObject(portal2)){

             

            i dont know why , does the bat become null before that for another reason

            thank you

            • 3. Re: error #2007
              thunderxlight11111 Community Member

              ohh sorry, forget that comment i missed somethig there

               

              here

               

              package  {

               

              import flash.display.MovieClip;

              import flash.events.Event;

               

               

              public class MAIN extends MovieClip {

               

               

               

              public function MAIN() {

              addEventListener(Event.ADDED_TO_STAGE,onAddedToStage)

              }

               

               

              public function onAddedToStage(event:Event):void

              {

              addEventListener(Event.ENTER_FRAME,onEnterFrame )

               

               

              }

               

               

               

              public function onEnterFrame (event:Event)

              {

              if (bat1){

              if (hero.hitTestObject(bat1) )

              {

              healthbar1.width -=1

              trace("HHH")

              }

              if (healthbar1.width >=  80 && healthbar1.width <=  100 ){

              zelda1.gotoAndPlay(1)

              }

              if (healthbar1.width >=  60 && healthbar1.width <=  80){

              zelda1.gotoAndPlay(2)

              }

              if (healthbar1.width >=  40 && healthbar1.width <=  60){

              zelda1.gotoAndPlay(3)

              }

              if (healthbar1.width >=  20 && healthbar1.width <=  40){

              zelda1.gotoAndPlay(4)

              }

              if (healthbar1.width >=  0 && healthbar1.width <=  20){

              zelda1.gotoAndPlay(5)

              }

              if (hero.hitTestObject(portal2)){

              var map2:MAP2 = new MAP2

              addChild(map2)

              if(map1.stage){

              removeChild(map1)

              }

              }

              }

               

               

              if(hero.hitTestObject(portal3)){

               

                    var map4:BACKGROUND = new BACKGROUND();

               

               

               

                   removeChild(bat1)

               

                   bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);  // this doesn't need to be done unless you added a listener outside the Bat1 classs

               

                   bat1 = null;

               

               

               

              }

              }

               

               

               

              }

               

               

              }

               

              the error still exist

              can i give you the fla file , maybe if you take closer look it will be easy to you , if you dont mind?

               

              thank you for your replay

              • 4. Re: error #2007
                kglad CommunityMVP

                use:

                 

                 

                 

                package  {

                 

                import flash.display.MovieClip;

                import flash.events.Event;

                 

                 

                public class MAIN extends MovieClip {

                 

                 

                 

                public function MAIN() {

                addEventListener(Event.ADDED_TO_STAGE,onAddedToStage)

                }

                 

                 

                public function onAddedToStage(event:Event):void

                {

                addEventListener(Event.ENTER_FRAME,onEnterFrame )

                 

                 

                }

                 

                 

                 

                public function onEnterFrame (event:Event)

                {

                if (bat1){

                if (hero.hitTestObject(bat1) )

                {

                healthbar1.width -=1

                trace("HHH")

                }

                if (healthbar1.width >=  80 && healthbar1.width <=  100 ){

                zelda1.gotoAndPlay(1)

                }

                if (healthbar1.width >=  60 && healthbar1.width <=  80){

                zelda1.gotoAndPlay(2)

                }

                if (healthbar1.width >=  40 && healthbar1.width <=  60){

                zelda1.gotoAndPlay(3)

                }

                if (healthbar1.width >=  20 && healthbar1.width <=  40){

                zelda1.gotoAndPlay(4)

                }

                if (healthbar1.width >=  0 && healthbar1.width <=  20){

                zelda1.gotoAndPlay(5)

                }

                }

                if (hero.hitTestObject(portal2)){

                var map2:MAP2 = new MAP2

                addChild(map2)

                if(map1.stage){

                removeChild(map1)

                }

                }

                 

                 

                if(hero.hitTestObject(portal3)){

                 

                      var map4:BACKGROUND = new BACKGROUND();

                 

                 

                 

                     removeChild(bat1)

                 

                     bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);  // this doesn't need to be done unless you added a listener outside the Bat1 classs

                 

                     bat1 = null;

                 

                 

                 

                }

                }

                 

                 

                 

                }

                 

                 

                }

                 

                the error still exist

                can i give you the fla file , maybe if you take closer look it will be easy to you , if you dont mind?

                 

                thank you for your replay

                • 5. Re: error #2007
                  thunderxlight11111 Community Member

                  i copied it then i pasted it , but the problem still the same?

                   

                  thank you again for your replay

                  • 6. Re: error #2007
                    kglad CommunityMVP

                    then you copied incorrectly.

                     

                    here's your code properly formatted so you can see the if(bat1) statement do not effect the portal2 hittest:

                     

                    package {

                        import flash.display.MovieClip;

                        import flash.events.Event;

                     

                        public class MAIN extends MovieClip {

                           

                            public function MAIN() {

                                addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);

                            }

                     

                            public function onAddedToStage(event:Event):void {

                                addEventListener(Event.ENTER_FRAME,onEnterFrame);

                            }

                            public function onEnterFrame(event:Event) {

                                if (bat1) {

                                    if (hero.hitTestObject(bat1)) {

                                        healthbar1.width-=1;

                                        trace("HHH");

                                    }

                                    if (healthbar1.width>=80&&healthbar1.width<=100) {

                                        zelda1.gotoAndPlay(1);

                                    }

                                    if (healthbar1.width>=60&&healthbar1.width<=80) {

                                        zelda1.gotoAndPlay(2);

                                    }

                                    if (healthbar1.width>=40&&healthbar1.width<=60) {

                                        zelda1.gotoAndPlay(3);

                                    }

                                    if (healthbar1.width>=20&&healthbar1.width<=40) {

                                        zelda1.gotoAndPlay(4);

                                    }

                                    if (healthbar1.width>=0&&healthbar1.width<=20) {

                                        zelda1.gotoAndPlay(5);

                                    }

                                }

                                if (hero.hitTestObject(portal2)) {

                                    var map2:MAP2=new MAP2  ;

                                    addChild(map2);

                                    if (map1.stage) {

                                        removeChild(map1);

                                    }

                                }

                                if (hero.hitTestObject(portal3)) {

                                    var map4:BACKGROUND=new BACKGROUND  ;

                                    removeChild(bat1);

                                    bat1.removeEventListener(Event.ENTER_FRAME,onEnterFrame);// this doesn't need to be done unless you added a listener outside the Bat1 classs

                                    bat1=null;

                                }

                            }

                        }

                    }

                    • 7. Re: error #2007
                      thunderxlight11111 Community Member

                      i copied it , but the problem still

                      sorry mr.kglad

                      here is the link of the project 

                      http://www.2shared.com/file/fIo-BLEw/project__4__.html

                       

                      thankyou for your replay

                      • 8. Re: error #2007
                        thunderxlight11111 Community Member

                        ohh , sorry forget that

                        the problem comes after going to the portal 3

                        • 9. Re: error #2007
                          kglad CommunityMVP

                          if this thread's problem is resolved, mark helpful/correct responses.

                          • 10. Re: error #2007
                            thunderxlight11111 Community Member

                            no the problem still ?!

                            i sent the link to you

                            here

                            http://www.2shared.com/file/fIo-BLEw/project__4__.html

                            maybe if you take closer look you will know the reason because you are very good in flash , but with me i did all my best but i couldn,t

                            thank you again for your replay

                            • 11. Re: error #2007
                              thunderxlight11111 Community Member

                              ok , i will try to do that, i mean to fix it alone

                               

                              thx mr.glad for your help

                              • 12. Re: error #2007
                                kglad CommunityMVP

                                you're welcome.

                                 

                                p.s.  someone else might download and correct your file but i generally don't download and correct files unless i'm hired.  if you have a question or problem with code, post it in the adobe forums and you'll probably get free help.

                                • 13. Re: error #2007
                                  thunderxlight11111 Community Member

                                  ohh , ok thx

                                  but i realy have project in my college i should finish it  before 3 months

                                  sorry mr.kglad iam not sure if i get this sentence " download and correct files unless i'm hired"

                                  i realy need that person ,help me and explain my errors , so can you help me and i can pay for that if you dont mind?

                                  if you have problem you can just ignore this message

                                  sorry again if i said something wrong

                                  • 14. Re: error #2007
                                    kglad CommunityMVP

                                    ok.

                                     

                                    i actually do download and correct files without being hired but only if people offer to pay for my time (like you did).  my feeling is, if it's not worth anything to the person with the problem, it's not worth my time.

                                     

                                    anyway, i downloaded and checked your file.  use:

                                     

                                              if (hero.hitTestObject(portal3)) {

                                                    var map4:BACKGROUND = new BACKGROUND();

                                                    if(bat1){

                                                        removeChild(bat1);

                                                        bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);// this doesn't need to be done unless you added a listener outside the Bat1 classs

                                                        bat1=null;

                                                    }

                                                }

                                    • 15. Re: error #2007
                                      thunderxlight11111 Community Member

                                      thank you alot mr.kglad.

                                      • 16. Re: error #2007
                                        kglad CommunityMVP

                                        you're welcome.