# Random Box

**URL:** <https://forum.kirupa.com/t/random-box/24565>\
**Category:** flash\
**Created:** [July 2, 2003, 6:11am UTC](https://forum.kirupa.com/t/random-box/24565 "2003-07-02T06:11:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unflux](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/unflux/32/7318_2.png) [@Unflux](https://forum.kirupa.com/u/Unflux)\
**Post date:** [July 2, 2003, 6:11am UTC](https://forum.kirupa.com/t/random-box/24565/1 "2003-07-02T06:11:55Z")

</div>

I did not write this code, but i cannot find where it’s wrong, so it  
doesn not work. It’s just supposed to move a box randomly along  
the x axis. Any thoughts?

```php
onClipEvent (load) {
	var limit = 600;
	var rand = random(limit);
	var currentPos = this._x;
	var speed = 5;
}
onClipEvent (enterFrame) {
	if (rand<=currentPos) {
		var count = rand;
		while (count>currentPos) {
			this._x -= speed;
			var count = count-speed;
			//var currentPos = this._x;
		}
	} else {
		var count = rand;
		while (count<currentPos) {
			this._x += speed;
			var count = count+speed;
			//var currentPos = this._x;
		}
	}
}

```

---

<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:** [July 2, 2003, 8:32am UTC](https://forum.kirupa.com/t/random-box/24565/2 "2003-07-02T08:32:52Z")

</div>

```auto

onClipEvent (load) {
    limit = 600;
    newPos = random(limit);
    speed = 5;
}
onClipEvent (enterFrame) {
    _x += (newPos-_x)/speed
}

```

```auto

onClipEvent (load) {
	limit = 600;
	newPos = random(limit);
	speed = 5;
}
onClipEvent (enterFrame) {
	if (_x<newPos) {
		_x += speed;
	}
	if (_x>newPos) {
		_x -= speed;
	}
}

```

btw, try to loose the flash 5 syntax :S
