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.
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;
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
The ELSE section has the potential to be activated all the time. If during the first loop an object fails the IF and lands in the ELSE, it is sent somewhere on the stage where it can't possibly pass the IF anymore, correct? You probably need to hold off sending things anywhere until all votes are in.
Well observed Ned! Thanks for that, sometimes it just needs a new pair eyes for looking at code cos I've been looking at it for the past 2 months! I'll have a think around that then.