Classic method that seems to work: have the enemy shoot out an invisible "detector" every few seconds so he knows if he can see anything in front of him. If that detector hits anything, it triggers the enemy to run his "shooting" function or group or however you have it set up.
Also check out the distance(x1,y1,x2,y2) thing when determining how far two things are from each other. That can help, too.