Collisions?

Well I’m an Amateur in AS2 coding so Here is the code i use for walking,

on(keyPress “<Up>”)
{ this._y -= 5;
this.gotoAndStop(2)}
on(keyPress “<Left>”)
{ this._x -= 5;
this.gotoAndStop(3)}
on(keyPress “<Right>”)
{ this._x += 5;
this.gotoAndStop(4)}
on(keyPress “<Down>”)
{ this._y += 5;
this.gotoAndStop(1)}

How would I make it so when My mc hits a wall it stops or bounces off?:ub: