# Testing Collision Between Multiple Object Of The Same Class

**URL:** https://forum.kirupa.com/t/testing-collision-between-multiple-object-of-the-same-class/282966
**Category:** flash
**Created:** [February 28, 2009, 4:06pm UTC](https://forum.kirupa.com/t/testing-collision-between-multiple-object-of-the-same-class/282966 "2009-02-28T16:06:54Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![DanDaMan](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@DanDaMan](https://forum.kirupa.com/u/DanDaMan)
#### Post date: [February 28, 2009, 4:06pm UTC](https://forum.kirupa.com/t/testing-collision-between-multiple-object-of-the-same-class/282966/1 "2009-02-28T16:06:54Z")

</div>

Okay, so I have a function on the Main Timeline that creates an instance of the class Ball once every 60 frames (1 second). In the class code for Ball I have this:

```auto
package {
    import flash.display.MovieClip;
    import flash.events.*;

    public class Ball extends MovieClip {
        private var _root:Object;
        private var distY:Number;
        public function Ball() {
            addEventListener(Event.ADDED_TO_STAGE, beginClass);
        }
        private function beginClass(event:Event):void {
            _root=MovieClip(root);
            addEventListener(Event.ENTER_FRAME, eFrame);
        }
        private function eFrame(event:Event):void {
            this.y+=1;
            for (var i:int=0; i<_root.numBalls; i++) {
                var mc:Ball=Ball(getChildAt(i));
                for (var j:int=0; j <_root.numBalls; j++) {
                    var mc2:Ball=Ball(getChildAt(j));
                    distY=Math.abs(this.y-_root.getChildByName("Ball"+i).y);
                    if (distY<=this.height) {
                        trace("STOP");
                    }
                }
            }
        }
    }
}

```

As you can see, I am trying to make it so that if two instances of the class Ball collide, then it should output “STOP”. But it isn’t working. Can anyone please tell me what I am doing wrong?
