Random movement; wall stopping

I have a rectrangle randomly moving in different directions in a grid pattern, and I want a wall pattern I have set up to prevent it from going through the wall (Basically, just have the walls stop it like a wall would.)

I dont want this done with regular hitTest by the way, which would involve like 578495634 wall MCs. Heres the AS I’m using for the random movement. Would the AS used for walls be included in this?

action = Math.ceil(Math.random()*100);
if (action>0 && action<20) {
tellTarget (e1) {
_y -= 15;
}
} else if (action>20 && action<40) {
tellTarget (e1) {
_y += 15;
}
} else if (action>40 && action<60) {
tellTarget (e1) {
_x += 15;
}
} else if (action>60 && action<80) {
tellTarget (e1) {
_x -= 15;
}
} else if (action>80 && action<100) {
}