A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Multiple collission detection problem

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    1

    Multiple collission detection problem

    Hi all, I am trying to create a movie where several movieclips move towards the centre of the screen and organise themselves. I havve the following code attached to the timeline, the clips move ok but dont interact. What am i doing wrong!?

    Code:
    target_mc  = ["mc0", "mc1", "mc2", "mc3"];
    
    movement  = function  () {  
    	numMcs  =  target_mc.length;
    	for (i=0; i<numMcs; i++) { 
    		McA  =  target_mc[i];
    
    		for (j=i+1; j<numMcs; j++) {
    			McB = target_mc[j];
    			temp_A = eval(McA);
    			temp_B = eval(McB); 
    			var xpos:Number = temp_A._x;
    			var ypos:Number = temp_A._y;
    			if (xpos>200) {
    				temp_A._x = xpos - 10;
    				if  (temp_A, hitTest(temp_B))  { 
    					temp_A._x = xpos;
    				}
    			};
    			if (xpos<200) {
    				temp_A._x = xpos + 10;
    				if (temp_A, hitTest(temp_B))  { 
    					temp_A._x = xpos;
    			 	}
    			};
    			if (ypos<200) {
    				temp_A._y = ypos + 10;
    				if (temp_A, hitTest(temp_B))  { 
    					temp_A._y = ypos;
    			 	}
    			};
    			if (ypos>200) {
    				temp_A._y = ypos - 10;
    				if (temp_A, hitTest(temp_B))  { 
    					temp_A._y = ypos;
    				}
    			}
    		}
    	}
    };
     
    this.onEnterFrame  = function()  {
    
    movement();
    
    };

  2. #2
    Check the syntax of your hit test. Right now, your if statements have a comma, which would mean an if with more than one argument. What you probably want is to change that to a period.

    Also, why not put the movie clips themselves in target_mc rather than strings holding their names? Then you wouldn't need to dereference them with eval.

    Some of your if blocks end with a semicolon. Not sure why.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center