# Stop object from moving further when collision occurs

**URL:** <https://forum.kirupa.com/t/stop-object-from-moving-further-when-collision-occurs/305254>\
**Category:** Uncategorized\
**Created:** [February 22, 2010, 12:23pm UTC](https://forum.kirupa.com/t/stop-object-from-moving-further-when-collision-occurs/305254 "2010-02-22T12:23:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebeccaLessay](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@RebeccaLessay](https://forum.kirupa.com/u/RebeccaLessay)\
**Post date:** [February 22, 2010, 12:23pm UTC](https://forum.kirupa.com/t/stop-object-from-moving-further-when-collision-occurs/305254/1 "2010-02-22T12:23:57Z")

</div>

As the title says: Stop object from moving further when collision occurs.

Right now I’m trying to make a sliding puzzle. So far I have a block which I can click and drag around, and a few walls which are the boundaries. What I’m trying to do is make an area where the block can slide within the boundaries. So when you try to drag the block into an direction it will stop, whether you got mouse\_down or mouse\_up. My script so far

```auto
stop();

//Sliding Blocks

MCBlock1.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
MCBlock1.addEventListener(MouseEvent.MOUSE_UP, dropIt);

function pickUp(event:MouseEvent):void {
	event.target.startDrag(true);
	
	
}

function dropIt(event:MouseEvent):void {
	event.target.stopDrag()}

//Colision

MCBlock1.addEventListener(Event.ENTER_FRAME, enter_frame);

function enter_frame(event:Event):void{
    
    if (MCBlock1.hitTestObject(MCwall1)) {
    	dropIt();
    } 
}

```

Anyone have any idea how to do this? Also I need to use a lot of boundaries, so if there’s a way to apply this script easily to several objects, please let me know.

Thanks in advance. ^^
