# Collision test among a series of objects

**URL:** <https://forum.kirupa.com/t/collision-test-among-a-series-of-objects/230465>\
**Category:** flash\
**Created:** [June 26, 2007, 1:58pm UTC](https://forum.kirupa.com/t/collision-test-among-a-series-of-objects/230465 "2007-06-26T13:58:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fw2803](https://avatars.discourse-cdn.com/v4/letter/f/e5b9ba/32.png) [@fw2803](https://forum.kirupa.com/u/fw2803)\
**Post date:** [June 26, 2007, 1:58pm UTC](https://forum.kirupa.com/t/collision-test-among-a-series-of-objects/230465/1 "2007-06-26T13:58:00Z")

</div>

Hello there  
I am simply testing one of my attempts.  
I have got three movieclips with instance name “object”, “obstacle1” and “obstacle2”. I put the following codes in the first frame:

```auto

obstacles = ["obstacle0","obstacle1"]
numofObs = obstacles.length
for (i=0;i<numofObs;i++) {
 obstacle = obstacles*
 if (_root.obstacle.hitTest(_root.object)) {
  _root.object.gotoAndStop(2)
  _root.txt = "Collision is detected"
 } else {
  _root.object.gotoAndStop(1)
  _root.txt = "No collision"
 }
 
}

```

“object” should change from blue to red if it collides with “obstacle1” or “obstacle2”. I use the following codes to make “object” move:

```auto

onClipEvent (load) {
 speed = 5
}
onClipEvent (enterFrame) {
 if (Key.isDown (Key.RIGHT)) {
  this._x += speed
 } else if (Key.isDown (Key.LEFT)) {
  this._x -= speed
 }
 if (Key.isDown (Key.UP)) {
  this._y -= speed
 } else if (Key.isDown (Key.DOWN)) {
  this._y += speed;
 }
} 

```

That’s all the codes I’ve got in the whole Flash. I read a tutorial from Kirupa earlier so I followed the instructions to create this. I wonder if I missed something or I misinterpreted something. Is there anything wrong in the scripts up there? “object” did not turn red when it is moved over “obstacle1” or “obstacle2”. Why?
