Enemy AI for platformers

Hi,I am making a platform game.I know how to make the character move,jump,attack…I just need some help with AI.I understood the enemy AI basics.I want the enemy to follow you when you reach a certain distance from him.
I want him to be able to block and attack.I saw some AI codes which were a little buggy and had syntax errors.most of them had sometging like

chancesofblock = random(100);
if(Key.isDown(Key.SPACE) && _root.hero.hitTest(_root.enemy)&&
chancesofblock <50)
//enemy’s death code here

The game is going to be a bit like http://www.newgrounds.com/portal/view/234470