# Stop moving?

**URL:** <https://forum.kirupa.com/t/stop-moving/12221>\
**Category:** Uncategorized\
**Created:** [January 28, 2003, 5:15pm UTC](https://forum.kirupa.com/t/stop-moving/12221 "2003-01-28T17:15:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fried](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@fried](https://forum.kirupa.com/u/fried)\
**Post date:** [January 28, 2003, 5:15pm UTC](https://forum.kirupa.com/t/stop-moving/12221/1 "2003-01-28T17:15:06Z")

</div>

How do I get an object to only move between two points if Iam moving it with the key arrows? The object moves right out the screen.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 28, 2003, 5:34pm UTC](https://forum.kirupa.com/t/stop-moving/12221/2 "2003-01-28T17:34:50Z")

</div>

use an if statement

if (this.\_x \> maxX) {  
this.\_x = maxX  
}  
if (this.\_x \< minX) {  
this.\_x = minX  
}  
if (this.\_y \> maxX) {  
this.\_y = maxX  
}  
if (this.\_y \< minX) {  
this.\_y = minX  
}

replace **maxX minX maxY** and **minY** with your values

or add a variable

maxX = whatever  
minX = whatever  
maxY = whatever  
minY = whatever

so it should be something like this:

```auto
onClipEvent (load) {
	maxX = whatever
	minX = whatever
	maxY = whatever
	minY = whatever
}
onClipEvent (enterFrame) {
	if (this._x > maxX) this._x = maxX
	if (this._x < minX) this._x = minX
	if (this._y > maxX) this._y = maxX
	if (this._y < minX) this._y = minX
}

```

hope it helps :beam:
