# Please help on colliding MC

**URL:** <https://forum.kirupa.com/t/please-help-on-colliding-mc/330390>\
**Category:** flash\
**Created:** [January 13, 2013, 2:35pm UTC](https://forum.kirupa.com/t/please-help-on-colliding-mc/330390 "2013-01-13T14:35:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggblade](https://avatars.discourse-cdn.com/v4/letter/e/3ab097/32.png) [@eggblade](https://forum.kirupa.com/u/eggblade)\
**Post date:** [January 13, 2013, 2:35pm UTC](https://forum.kirupa.com/t/please-help-on-colliding-mc/330390/1 "2013-01-13T14:35:02Z")

</div>

I wanted to create an android app using accelerometer in as3 based on the template.

\*\*I have 2 MC : \*\*  
-ball (the red one)  
-balla (the green one)

The accelerometer things are fine,but **what I want is both of the balls collide not overlaying each other.**  
What sort of code that I need to write?:q:

**Here’s my current code :**

```auto

import flash.events.Event;

var accelX:Number;
var accelY:Number;

var fl_Accelerometer:Accelerometer = new Accelerometer();
fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);
function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void
{
    accelX = event.accelerationX;
    accelY = event.accelerationY;
}

ball.addEventListener(Event.ENTER_FRAME, moveBall);
function moveBall(evt:Event){
    ball.x -= accelX*20;
    ball.y += accelY*20;
    
    if(ball.x > (480-ball.width/2)){
        ball.x = 480-ball.width/2;
    }
    if(ball.x < (0+ball.width/2)){
        ball.x = 0+ball.width/2;
    }
    if(ball.y > (800-ball.width/2)){
       ball.y = 800-ball.width/2;
    }
    if(ball.y < (0+ball.width/2)){
        ball.y = 0+ball.width/2;
    }
}

balla.addEventListener(Event.ENTER_FRAME, moveBalla);
function moveBalla(evt:Event){
    balla.x -= accelX*20;
    balla.y += accelY*20;
    
    if(balla.x > (480-balla.width/2)){
        balla.x = 480-balla.width/2;
    }
    if(balla.x < (0+balla.width/2)){
        balla.x = 0+balla.width/2;
    }
    if(balla.y > (800-balla.width/2)){
       balla.y = 800-balla.width/2;
    }
    if(balla.y < (0+balla.width/2)){
        balla.y = 0+balla.width/2;
    }
}

```

Thank you.
