here is the code for my enemy
Dir = -1;
Action = “Stand”;
Direction = “Left”;
Timer = 20;
Attack = false;
Attacked = false;
this.onEnterFrame = function() {
gotoAndStop("Regular “+Action+” "+Direction);
var Distance = _root.Hero._x-_x;
//-----------------------------------------//
if (Distance>0) {
Direction = “Right”;
Dir = 1;
} else {
Direction = “Left”;
Dir = -1;
}
//-----------------------------------------//
if (_root.Hero.Action == “Attack” && Math.abs(Distance)<=_width) {
Action = “Block”;
} else if (Math.abs(Distance)<200) {
if (Attacked) {
Action = “Walk”;
_x += -Dir2.5;
Timer -= .5;
if (Timer == 0) {
Timer = 25;
Attacked = false;
}
} else {
if (Math.abs(Distance)>_width) {
_x += Dir2.5;
Action = “Walk”;
} else if (Math.abs(Distance)<=_width) {
if (Attacked == false) {
Action = “Attack”;
} else if (Attacked == true&&Math.abs(Distance)<=_width-6) {
Action = “Block”;
}
}
}
} else if (Math.abs(Distance)<200) {
Action = “Stand”;
}
};
there is a slight problem, i want the enemy to finish attacking once he has started, even when the hero moves away.