Move container sprite according to mouse movement

Hi All,

Currently I’m developing a game where there is a object which follows mouse. Also there are other objects and a map on the screen.I want all of background content(whole map and other objects) to move when user moves mouse left or right. That is, if user moves mouse on right side then all content(except object which moves as per mouse) should move left side so that user can see remaining part of map on the right side.

As of now I have created new Container sprite in which I have added all of my objects and map. So when user moves the mouse right, I move the container sprite to left so it looks all stuff moves to left. Code looks like as below


var pt:Point = new Point(character.x, character.y);
pt = dori.localToGlobal(pt);
if (pt.x > (stage.width * 0.5))
{
		container.x -= 5;
}

Structure of project is such that, I add Container directly to stage. and this container contains everything like map, character and other objects.

Now issue is that as soon as mouse goes beyond middle of stage…it creates distance between mouse location and character…!! I mean it does move according to mouse but some distance get created between mouse and character. and this distance keeps increasing as I continue to move mouse away from center of stage!!

I’m really stuck with this issue. Please someone help with this. I hope I have explained this well. Let me know if you need more info but please help.