2 Replies Latest reply on Jun 30, 2009 8:21 AM by keithwoods

    'IF' and 'ELSE' conditionals not working?

    keithwoods Level 1

      I've got a function which uses a 'hitTestObject' test if two moive clips are touching each other. A FOR loop has been used to run through all the zones, to check if they've been touched. Within this FOR loop is an IF condition which then locks the ball to that particular zone if the ball and zone are touching. The ELSE statement sends the ball back to a random place on the stage if they're not toucing.

      However, the IF statement seems to be getting bypassed. Whenever a ball is dragged over a zone and the mouse is released, rather than locking to that zone's x and y positions, it gets placed randomly on the stage...i.e. the ELSE statement is being activated all the time?!

      I've commented out the ELSE condition and the IF works fine on it's own, it's just when the ELSE condition is included the IF is bypassed. Any pointers greatly appreciated.

      ActionScript Code:
      private function zoneFill(event:MouseEvent):void
                      for (var i:uint = 0; i<=8; i++)
                          var index:Number = event.target.name.substring(5,6);

                          if(event.target.hitTestObject(zone[i]) && zoneFull[i] == false && event.target._ballPlaced[index]== false)
                              event.target.x = zone[i].x;
                              event.target.y = zone[i].y;
                              event.target.scaleX = 1;
                              event.target.scaleY = 1;
                              zoneFull[i] = true;
                              event.target._ballPlaced[index] = true;
                              event.target.removeEventListener(MouseEvent.MOUSE_UP, zoneFill);
                              trace(event.target.name + " has touched " + zone[i]);
                              event.target.x=Math.random() * 900 + 50;
                              event.target.y=Math.random()* 55 + 550;
                              trace(event.target.name + " has not touched a zone.");
      }// end of zoneFill function