The way I did this in my game was to put the whole game in an object container (mc_world) and then move that container in the opposite direction of the hero (while making sure you shift it relative to the "screen"). Just make sure that everything in your game is in this container (including your hero). I made a seperate CameraController class because I had other functions in there. But basically this is the function I used to center the "camera" around an object:
ActionScript Code:
// Change these to match your screen size:
public const SCREEN_WIDTH = 550;
public const SCREEN_HEIGHT = 400;
// Call this function every frame. mc_object is the object you want to center on.
// mc_world is the container of the entire game.
public function lookAt(mc_object,mc_world):void{
mc_world.x = SCREEN_WIDTH/2.0 - mc_object.x;
mc_world.y = SCREEN_HEIGHT/2.0 - mc_object.y;
}
// Sample main loop:
function mainLoop(e:Event):void{
// ...
lookAt(myHero,myWorld);
// ...
}
NOTE: I had to change the lookAt function to simplify it for this case (because I used Box2D in my game). So I'm not sure if it works 100% now that I changed it. But it did work in my game.
You then don't have to worry about individual entities (enemies, etc). You move your hero like you normally would. Since the hero is in mc_world, he will move relative to that world. But lookAt moves the entire world so that the hero is centered (or any other object you pass it).
Hope that helps. Good luck.
PS. I'm not sure if this is the best or most efficient way of doing things. This is just the way I did it and it worked fine for me.