Object Randomizer (with Collision Detection)

Just wondering, I need a little help here. I set up a basic engine with two objects in it: a “wall” and an “enemy”. I want to accomplish three tasks with this engine:

  1. Randomly assign “enemy” a position when the movie loads. (check)
  2. If enemy’s position involves contact with the wall, reassign his position. (need help)
  3. Repeat the above process until enemy has a static, stable, non-wall-touching position. (need help)

Here’s my current code in the frame.

_root.enemycount = 1;
//sets enemycount as a variable
_root.onMouseDown = function() {
	//when clicked, the enemy is duplicated
	duplicateMovieClip("enemy", "enemy"+enemycount, enemycount);

Here’s my current code in the enemy.

onClipEvent (load) {
	//randomizes the enemy's position on starting up the movie
	this._x = Math.floor(Math.random()*500);
	this._y = Math.floor(Math.random()*350);
	//hitvalue shows whether or not it has hit the wall and deleted itself
	if (_root.wall.hitTest(this._x, this._y, true)) {
		_root.hitvalue = 1;
	} else {
		_root.hitvalue = 0;
	//redundant statement (because I don't know how to do object NOT hittesting
	if (_root.wall.hitTest(this._x, this._y, true)) {
		//reassigns the value ONCE if it hits the wall
		this._x = Math.floor(Math.random()*500);
		this._y = Math.floor(Math.random()*350);
	//To move the original "enemy" movie clip out of view.      
	if (_name == "enemy") {
		_x = -700;

As you can see, my problem here is that it only checks for colliding with the wall once. This means that there is a possibility that the movie clip might be removed and not appear onscreen due to failing both checks. The “hitvalue” shows whether or not the enemy hits the wall when you click, which also resets the value of the enemy.

Below is the .fla of what I have done. To operate the flash, just click and the “enemy” will keep reassigning its position. My ultimate goal is to be able to manipulate “enemycount” and spawn any given number of enemies who are not in walls, but that is some ways away.

How do I make an infinite loop that keeps checking until the movie clip gets a “good” position (one not touching the wall?)