Need help with ai

im making a fighting game and i need an opponent to fight back atm ive got
mc for standingin frame 1 walking frame2 and fighting frame 3-4 what type of code do i need so that he will walk and attack, and do damage?

is the game top down or side on?
for side on

if (char._x-range>enamy._x){
enamy.gotoAndStop(2)
enamy._x+=speed
} else if (char._x+range<enamy._x){
enamy.gotoAndStop(2)
enamy._x-=speed
} else if (char._x+range>enamy._x){
enamy.gotoAndStop(3)
}else if (char._x-range<enamy._x){
enamy.gotoAndStop(4)
}

some thing like this might work, or atlest is some where to start

(note; my speelchek is not working. supid MSword)