Bounce of wall with direction changes

Hi Guys,

I have this following situation.

Basically, I want my balls to move around a border and bounce off the walls when it hit the walls.

I have this done up and working.
Here an example of what I had achieve
http://64.13.207.72/download/arrow.swf

But upon hitting the wall, I want the balls to rotated to a reflect the correct direction also, this part I’m stuck =(

Please click on this link to have an idea of what I mean
http://64.13.207.72/download/example.jpg

The script is use is as follow:


onClipEvent (load) {
	fanX = this._x;
	fanY = this._y;
	leftWall = 0;
	rightWall = 600;
	topWall = 150;
	bottomWall = 400;
	fanRadius = this._width/2;
	distX = (Math.random()*3)-1.5;
	distY = (Math.random()*3)-1.5;
}
//
//
//
onClipEvent (enterFrame) {
	//
	fanX = fanX+distX;
	fanY = fanY+distY;
	this._x = fanX;
	this._y = fanY;
	// check right wall
	if (fanX+fanRadius>rightWall) {
		overshoot = (fanX+fanRadius)-rightWall;
		fanX -= overshoot*2;
		distX *= -1;
	}
	// check left wall
	if (fanX-fanRadius<leftWall) {
		overshoot = leftWall-(fanX-fanRadius);
		fanX += overshoot*2;
		distX *= -1;
	}
	// check bottom wall
	if (fanY+fanRadius>bottomWall) {
		overshoot = (fanY+fanRadius)-bottomWall;
		fanY -= overshoot*2;
		distY *= -1;
	}
	// check top wall
	if (fanY-fanRadius<topWall) {
		overshoot = topWall-(fanY-fanRadius);
		fanY += overshoot*2;
		distY *= -1;
	}
}

The file can be download via this link
http://64.13.207.72/download/arrow.zip

Any input? Thanks =)
:rabbit: