23 Replies Latest reply on Nov 2, 2011 8:04 AM by kglad

    Hit Test Error...

    McbainGames11 Level 2

      Hey,

       

      Code:

       

      addEventListener(Event.ENTER_FRAME, Pixel_Perfect);
      
      function Pixel_Perfect(e:Event):void
      {
      
          var blueRect:Rectangle = Bird_1.getBounds(this);
          var blueOffset:Matrix = Bird_1.transform.matrix;
          blueOffset.tx = Bird_1.x - blueRect.x;
          blueOffset.ty = Bird_1.y - blueRect.y;
      
          var blueClipBmpData = new BitmapData(blueRect.width,blueRect.height,true,0);
          blueClipBmpData.draw(Bird_1, blueOffset);
      
          var redRect:Rectangle = enemy1.getBounds(this);
          var redClipBmpData = new BitmapData(redRect.width,redRect.height,true,0);
      
          var redOffset:Matrix = enemy1.transform.matrix;
          redOffset.tx = enemy1.x - redRect.x;
          redOffset.ty = enemy1.y - redRect.y;
      
          redClipBmpData.draw(enemy1, redOffset);
      
          var rLoc:Point = new Point(redRect.x,redRect.y);
          var bLoc:Point = new Point(blueRect.x,blueRect.y);
      
          if (redClipBmpData.hitTest(rLoc,
          255,
          blueClipBmpData,
          bLoc,
          255
            ))
          {
      
             life_1++;
             trace(life_1);
      
          }
          blueClipBmpData.dispose();
          redClipBmpData.dispose();
      }
      
      //Enemy1 is a class is that makes a difference
      //I didn't write this code as i am not this advanced yet but really needed this script, this script normally works but now i am recieving errors 
      

       

      Error:

       

      ArgumentError: Error #2015: Invalid BitmapData.
          at flash.display::BitmapData/ctor()
          at flash.display::BitmapData()
          at IceMountain_fla::MainTimeline/Pixel_Perfect()
      

       

       

      Thanks.

        • 1. Re: Hit Test Error...
          kglad Adobe Community Professional & MVP

          use the trace function to ensure both objects exist and, if so, click file/publish settings/flash/ and tick "permit debugging".  retest to locate the problematic line number.

          • 2. Re: Hit Test Error...
            McbainGames11 Level 2

            Another Question:

             

            How can i make a simple hit test for each block in my newchars class.

             

            I want my instance(Bird_1) to gotoAndPlay(5); when it collides with one of my blocks created by the one class.

             

            How to do this? I think the reason is that newchars is a class.

             

            if(Bird_1.hitTestObject(enemy1))

            {

             

            gotoAndPlay(5);

             

            }

             

            ^^ This doesn't work! ^^

             

            Thanks for Help.

             

            Date: Sun, 23 Oct 2011 10:01:55 -0600

            From: forums@adobe.com

            To: mcbain97@hotmail.com

            Subject: Hit Test Error...

             

             

             

             

             

             

                  

                       

                       

                       

                Re: Hit Test Error...

             

             

                created by kglad in Flash Pro - General - View the full discussion

             

             

             

            use the trace function to ensure both objects exist and, if so, click file/publish settings/flash/ and tick "permit debugging".  retest to locate the problematic line number.

             

             

                 Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/3986208#3986208

                 To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/3986208#3986208. In the Actions box on the right, click the Stop Email Notifications link.

                  

                 Start a new discussion in Flash Pro - General by email or at Adobe Forums

              For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

            • 3. Re: Hit Test Error...
              kglad Adobe Community Professional & MVP

              i don't see anything about a newchars class.

              • 4. Re: Hit Test Error...
                McbainGames11 Level 2

                That is a class that creates objects and makes them fall , u helped me with it in other thread.

                 

                How to make work?

                 

                And

                 

                Do classs make hit test harders and or can cause ploblems?

                 

                Thanks.

                 

                Sent from my iPhone

                • 5. Re: Hit Test Error...
                  kglad Adobe Community Professional & MVP

                  what class is Pixel_Perfect() in?

                  • 6. Re: Hit Test Error...
                    McbainGames11 Level 2

                    Here is the frame code source:

                     

                    stop();
                    
                    //Game Chances
                    star_1.alpha = 0.5;
                    star_2.alpha = 0.5;
                    star_3.alpha = 0.5;
                    
                    var life_1:int = 2;
                    
                    if(life_1 == 1)
                    {
                    
                        star_1.alpha = 1;
                        star_2.alpha = 0.5;
                        star_3.alpha = 0.5;
                    
                    } else if(life_1 == 2)
                    {
                    
                        star_1.alpha = 1;
                        star_2.alpha = 1;
                        star_3.alpha = 0.5;
                    
                    } else if(life_1 == 3)
                    {
                    
                        star_1.alpha = 1;
                        star_2.alpha = 1;
                        star_3.alpha = 1;
                    
                    } else if(life_1 == 0)
                    {
                    
                        gotoAndStop(5);
                    
                    } else {
                    
                        star_1.alpha = 0.5;
                        star_2.alpha = 0.5;
                        star_3.alpha = 0.5;
                    
                    }
                    
                    //Hit Test.. I am using a simple version now 
                    
                    /*This is the error line*/ if(Bird_1.hitTestObject(enemy1))
                    {
                    
                        life_1++;
                        trace(life_1);
                        trace('Something is Happening...');
                    
                    } else {
                        trace('Nothing is Happening...');    
                    }
                    
                    //Rows and Cubes Class
                    var rowNum:int = 10;
                    
                    for (var i:int=0; i<rowNum; i++)
                    {
                    
                        var enemy1:newchars = new newchars(i);
                    
                        enemy1.addEventListener(Event.ENTER_FRAME, GravityFall);
                    
                        addChild(enemy1);
                    
                    }
                    
                    function GravityFall(event:Event):void
                    {
                    
                        var enemy1:newchars = newchars(event.currentTarget);
                    
                        enemy1.y +=  2;
                    
                    }
                    
                    //Timer
                    var timer:int = 0;
                    
                    var TimerSpeed:uint = 1000;
                    var MyTimer = new Timer(TimerSpeed);
                    MyTimer.addEventListener(TimerEvent.TIMER, TimerHandler);
                    
                    function TimerHandler(e:TimerEvent):void
                    {
                    
                        timer +=  1;
                    
                        if(timer == 50)
                        {
                    
                    
                            removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler100);
                            MyTimer.removeEventListener(TimerEvent.TIMER, TimerHandler);
                    
                            MyTimer.stop();
                            gotoAndPlay(4);
                    
                        }
                        else if(timer == 45)
                        {
                    
                            Bird_1.gotoAndPlay(11);
                    
                        }
                    
                    }
                    
                    //Plain Enter Frame Event
                    addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler100);
                    
                    
                    function fl_EnterFrameHandler100(event:Event):void
                    {
                    
                        Bird_1.x = mouseX;
                    
                        MyTimer.start();
                    
                    }
                    

                     

                    Error:

                     

                    Attempting to launch and connect to Player using URL C:\Users\Brendon Battye\Desktop\Ice Mountain\Ice Mountain.swf
                    [SWF] C:\Users\Brendon Battye\Desktop\Ice Mountain\Ice Mountain.swf - 131232 bytes after decompression
                    TypeError: Error #2007: Parameter hitTestObject must be non-null.
                        at flash.display::DisplayObject/_hitTest()
                        at flash.display::DisplayObject/hitTestObject()
                        at IceMountain_fla::MainTimeline/frame3()[IceMountain_fla.MainTimeline::frame3:45]
                        at flash.display::MovieClip/gotoAndPlay()
                        at IceMountain_fla::Symbol4_4/frame6()[IceMountain_fla.Symbol4_4::frame6:1]
                    Debug session terminated.
                    

                     

                    Thanks for your time.

                    • 7. Re: Hit Test Error...
                      kglad Adobe Community Professional & MVP

                      it looks like you have no enemy1 instances when your hittest first executes.

                       

                      enemy1 instances are created after your hittest.  and it appears there's more than 1 enemy1 and you have no way to reference them all in your hittest or anywhere else after you create them.

                      • 8. Re: Hit Test Error...
                        McbainGames11 Level 2

                        So would i have to implement something into my newchars class?

                         

                        If i do then i need to make a class for importing the bird also because i would have no instance to reference it in my hit test( in the class ).

                         

                        What do you suggest, I could try what i said.

                         

                        Date: Tue, 25 Oct 2011 08:30:31 -0600

                        From: forums@adobe.com

                        To: mcbain97@hotmail.com

                        Subject: Hit Test Error...

                         

                         

                         

                         

                         

                         

                              

                                   

                                   

                                   

                            Re: Hit Test Error...

                         

                         

                            created by kglad in Flash Pro - General - View the full discussion

                         

                         

                         

                        it looks like you have no enemy1 instances when your hittest first executes. enemy1 instances are created after your hittest.  and it appears there's more than 1 enemy1 and you have no way to reference them all in your hittest or anywhere else after you create them.

                         

                         

                             Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/3989358#3989358

                             To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/3989358#3989358. In the Actions box on the right, click the Stop Email Notifications link.

                              

                             Start a new discussion in Flash Pro - General by email or at Adobe Forums

                          For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

                        • 9. Re: Hit Test Error...
                          kglad Adobe Community Professional & MVP

                          your setup looks problematic.  it appears you have code scattered across more than 1 frame in your main timeline.  it's possible you have code in other timelines.

                           

                          you should have an enemy class and a bird class and possibly other classes.  you should have a document class the creates enemy and bird instances and keeps track of them all and executes your hittest.

                          • 10. Re: Hit Test Error...
                            McbainGames11 Level 2

                            So to make the hit test i make the bird imported by a class.

                             

                            And should i make the hit test a class and inherit bird class and newchars class since they are the 2 things i want to detect collisions?

                             

                            Simple Yes or No for that question and i think i know what to do

                             

                            Thanks.

                             

                            Date: Tue, 25 Oct 2011 15:26:22 -0600

                            From: forums@adobe.com

                            To: mcbain97@hotmail.com

                            Subject: Hit Test Error...

                             

                             

                             

                             

                             

                             

                                  

                                       

                                       

                                       

                                Re: Hit Test Error...

                             

                             

                                created by kglad in Flash Pro - General - View the full discussion

                             

                             

                             

                            your setup looks problematic.  it appears you have code scattered across more than 1 frame in your main timeline.  it's possible you have code in other timelines. you should have an enemy class and a bird class and possibly other classes.  you should have a document class the creates enemy and bird instances and keeps track of them all and executes your hittest.

                             

                             

                                 Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/3990078#3990078

                                 To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/3990078#3990078. In the Actions box on the right, click the Stop Email Notifications link.

                                  

                                 Start a new discussion in Flash Pro - General by email or at Adobe Forums

                              For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

                            • 11. Re: Hit Test Error...
                              kglad Adobe Community Professional & MVP

                              unless it would make your document class unwieldy, i would create the birds and enemies in the document class and push the instances into a birdA array and an enemyA array.  i would then use those arrays in a document class hittest.

                              • 12. Re: Hit Test Error...
                                McbainGames11 Level 2

                                Can i have a couple lines of code to know where to begin please?

                                 

                                So basically what information do i put in each array and where from and how? Once i see some code and understand it i can then extend upon it but right now i don't fully understand

                                 

                                This is new things im learning and i am finding this hard because it is my weakness :P

                                 

                                Thanks again.

                                 

                                Date: Tue, 25 Oct 2011 18:11:08 -0600

                                From: forums@adobe.com

                                To: mcbain97@hotmail.com

                                Subject: Hit Test Error...

                                 

                                 

                                 

                                 

                                 

                                 

                                      

                                           

                                           

                                           

                                    Re: Hit Test Error...

                                 

                                 

                                    created by kglad in Flash Pro - General - View the full discussion

                                 

                                 

                                 

                                unless it would make your document class unwieldy, i would create the birds and enemies in the document class and push the instances into a birdA array and an enemyA array.  i would then use those arrays in a document class hittest.

                                 

                                 

                                     Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/3990282#3990282

                                     To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/3990282#3990282. In the Actions box on the right, click the Stop Email Notifications link.

                                      

                                     Start a new discussion in Flash Pro - General by email or at Adobe Forums

                                  For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

                                • 13. Re: Hit Test Error...
                                  kglad Adobe Community Professional & MVP

                                  package{

                                   

                                  import ...

                                  public class Main extends MovieClip

                                   

                                  private var enemyA:Array=[]

                                  private var birdA:Array=[];

                                   

                                  public function Main(){

                                  createEnemyF();

                                  createBirdF();  //  add this function

                                  this.addEventListener(Event.ENTER_FRAME,loopF);

                                  }

                                   

                                  private function createEnemyF():void{

                                  for (var i:int=0; i<rowNum; i++){
                                  var enemy1:newchars = new newchars(i);
                                  enemyA.push(enemy1);
                                  addChild(enemy1);
                                  }

                                  }

                                   

                                  private function loopF(e:Event):void{

                                  updateEnemyPositionsF();  // add these 3 functions

                                  updateBirdPositionsF();

                                  hitTestF();

                                  }

                                   

                                  }

                                  }

                                  • 14. Re: Hit Test Error...
                                    McbainGames11 Level 2

                                    All that code i am unfamiliar is hurting my brain lol, i don't want you TO DO IT ALL but can you give me step by step instruciton of why the code is there and do it for 1 class and i will work the other please, source:

                                     

                                    package

                                    {

                                     

                                        import flash.display.MovieClip;

                                     

                                        import flash.events.Event;

                                     

                                     

                                        public class newchars extends MovieClip

                                        {

                                     

                                            private var rowNum:int;

                                     

                                            private var gap:int = 100;

                                     

                                            private var obj_no = 2;

                                     

                                     

                                            public function newchars(_rowNum:int = 1)

                                            {

                                     

                                                rowNum = _rowNum;

                                     

                                                this.addEventListener(Event.ADDED_TO_STAGE, addtostage);

                                     

                                            }

                                     

                                            private function addtostage(event:Event):void

                                            {

                                     

                                                for (var i:int = 0; i < obj_no; i++)

                                                {

                                     

                                                    var newchar1:MovieClip = new mychar();

                                     

                                                    addChild(newchar1);

                                     

                                                    newchar1.x = Math.random() * stage.stageWidth - newchar1.width;

                                     

                                                    newchar1.y =  -  rowNum * (gap + newchar1.height) - 30.65;

                                     

                                                }

                                     

                                            }

                                     

                                        }

                                     

                                     

                                    • 15. Re: Hit Test Error...
                                      kglad Adobe Community Professional & MVP

                                      that's going to be a huge mess.  remove the newchars() class.  it's doing nothing useful.

                                       

                                      use:

                                       

                                      private function createEnemyF():void{

                                      for (var i:int=0; i<rowNum; i++){

                                      for(var j:int=0;j<obj_no;j++){
                                      var enemy1:mychar = new mychar();

                                      enemy1.x = Math.random() * stage.stageWidth - enemy1.width;

                                      enemy1.y =  -  i* (gap + enemy1.height) - 30.65;
                                      enemyA.push(enemy1);
                                      addChild(enemy1);
                                      }

                                      }

                                      }

                                      • 16. Re: Hit Test Error...
                                        McbainGames11 Level 2

                                        Could i please have steps of what to do and where to do each step please?

                                         

                                        Where does tge code u wrote go and newchar is needed to make enemies!

                                         

                                        Sent from my iPhone

                                        • 17. Re: Hit Test Error...
                                          kglad Adobe Community Professional & MVP

                                          use a real web-enabled device so you can see my previous two messages.

                                          • 18. Re: Hit Test Error...
                                            McbainGames11 Level 2

                                            Can u answer question in my last comment please

                                             

                                            Sent from my iPhone

                                            • 19. Re: Hit Test Error...
                                              kglad Adobe Community Professional & MVP

                                              package{

                                               

                                               

                                               

                                              import ...

                                               

                                              public class Main extends MovieClip

                                               

                                               

                                               

                                              private var enemyA:Array=[]

                                               

                                              private var birdA:Array=[];

                                               

                                               

                                               

                                              public function Main(){

                                               

                                              createEnemyF();

                                               

                                              createBirdF();  //  add this function

                                               

                                              this.addEventListener(Event.ENTER_FRAME,loopF);

                                               

                                              }

                                               

                                               

                                               

                                              private function createEnemyF():void{

                                               

                                              for (var i:int=0; i<rowNum; i++){

                                               

                                              for(var j:int=0;j<obj_no;j++){

                                              var enemy1:mychar = new mychar();

                                               

                                              enemy1.x = Math.random() * stage.stageWidth - enemy1.width;

                                               

                                              enemy1.y =  -  i* (gap + enemy1.height) - 30.65;

                                              enemyA.push(enemy1);

                                              addChild(enemy1);

                                              }

                                               

                                              }

                                               

                                              }

                                               

                                               

                                               

                                              private function loopF(e:Event):void{

                                               

                                              updateEnemyPositionsF();  // add these 3 functions

                                               

                                              updateBirdPositionsF();

                                               

                                              hitTestF();

                                               

                                              }

                                               

                                               

                                               

                                              }

                                               

                                              }

                                              1 person found this helpful
                                              • 20. Re: Hit Test Error...
                                                McbainGames11 Level 2

                                                Please answer me these  questions with good explanation and i think this is question closed

                                                 

                                                What is the array doing ie push and blank array variable?

                                                 

                                                What is enemyA doing when i have enemy1 added?

                                                 

                                                What does push do wheb you pushed enemyA?

                                                 

                                                The function updateEnemyF(); is to do what because we have already added the enemy in right positions?

                                                 

                                                You are life saver, without this forum and ur help i wouldnt become more advanced as your teaching me,thanks!

                                                 

                                                Sent from my iPhone

                                                • 21. Re: Hit Test Error...
                                                  kglad Adobe Community Professional & MVP

                                                   

                                                   

                                                  What is the array doing ie push and blank array variable?

                                                  What is enemyA doing when i have enemy1 added?

                                                  What does push do wheb you pushed enemyA?

                                                  the push() method adds the argument to the array.  ie, enemyA.push(enemy1), adds enemy1 to enemyA.  this gives you a way to reference all existing enemies (by looping through enemyA).

                                                   


                                                   

                                                  The function updateEnemyF(); is to do what because we have already added the enemy in right positions?

                                                  it updates the enemies positions.  if none of your enemies move, this is not needed.  but if they move, this is needed to update their positions

                                                   

                                                  1 person found this helpful
                                                  • 22. Re: Hit Test Error...
                                                    McbainGames11 Level 2

                                                    I think i can work this out now, thanks for help this is getting a bit more advanced than i am used to so just getting my head around it but i think i got it now!

                                                     

                                                    thanks again i know you put in good effort.

                                                    • 23. Re: Hit Test Error...
                                                      kglad Adobe Community Professional & MVP

                                                      you're welcome.