Skip navigation
Currently Being Moderated

error #2007

Aug 15, 2012 4:08 AM

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

 
Replies
  • kglad
    72,220 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 15, 2012 6:49 AM   in reply to thunderxlight11111

    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))

     
    |
    Mark as:
  • kglad
    72,220 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 16, 2012 6:52 AM   in reply to thunderxlight11111

    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

     
    |
    Mark as:
  • kglad
    72,220 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 16, 2012 7:04 AM   in reply to thunderxlight11111

    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;

                }

            }

        }

    }

     
    |
    Mark as:
  • kglad
    72,220 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 16, 2012 8:15 AM   in reply to thunderxlight11111

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

     
    |
    Mark as:
  • kglad
    72,220 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 16, 2012 9:38 PM   in reply to thunderxlight11111

    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.

     
    |
    Mark as:
  • kglad
    72,220 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 17, 2012 6:44 AM   in reply to thunderxlight11111

    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;

                    }

                }

     
    |
    Mark as:
  • kglad
    72,220 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 18, 2012 7:24 AM   in reply to thunderxlight11111

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points