3 Replies Latest reply on Jun 15, 2007 7:27 AM by kglad

    hittesting for multiple objects

    Jimmathy
      I have 7 "block" movie clips that I have manually placed on the stage. All of which have the instance name of "block". when I run the actionscript:
      speed = 5;
      function charMove(){
      if(Key.isDown(Key.RIGHT)){
      if(_root.char.hitTest(_root.block)){}
      else{
      _root.char._x += speed;
      dir=1;}
      _root.char.gotoAndStop(4);
      }
      else if(Key.isDown(Key.LEFT)){
      if(_root.char.hitTest(_root.block)){}
      else{
      _root.char._x -= speed;
      dir=3;
      }
      _root.char.gotoAndStop(2);
      }
      else if(Key.isDown(Key.UP)){
      if(_root.char.hitTest(_root.block)){}
      else{
      _root.char._y -= speed;
      dir=4;
      }
      _root.char.gotoAndStop(1);
      }
      else if(Key.isDown(Key.DOWN)){
      if(_root.char.hitTest(_root.block)){}
      else{
      _root.char._y += speed;
      dir=2;
      }
      _root.char.gotoAndStop(5);
      }
      else{
      if(dir==1){
      _root.char.gotoAndStop(6);
      if(_root.char.hitTest(_root.block)){
      _root.char._x -= 5;
      }
      }
      else if(dir==2){
      _root.char.gotoAndStop(7);
      if(_root.char.hitTest(_root.block)){
      _root.char._y -= 5;
      }
      }
      else if(dir==3){
      _root.char.gotoAndStop(8);
      if(_root.char.hitTest(_root.block)){
      _root.char._x += 5;
      }
      }
      else if(dir==4){
      _root.char.gotoAndStop(9);
      if(_root.char.hitTest(_root.block)){
      _root.char._y += 5;
      }
      }}}

      It picks only one of the 7 blocks to run the hitTest for. How can i make it so all the blocks are tested for with out making the code extra long testing fo each specific one?

      thnks