mouseX/Y confusion when dragging a child of a container

algro picture algro · May 26, 2011 · Viewed 12.5k times · Source

I've got a grid of images which are added to a imagecontainer(Sprite) in a class. When I click a button, the imagecontainer gets tweened(scaled) to 0.2 Now I would like to start dragging around the images. on mouse-down I add an enterFrame Event:

function onEnterFrame(e:Event):void
{
  imagecontainer.image.x = this.mouseX;
  imagecontainer.image.y = this.mouseY;

}

Unfortunately the image is never on the mouseposition but has a increasing/decreasing offset to the mouse pointer. The alternative, startDrag/stopDrag works perfectly, but I still need the mouseX/mouseY for placing the image on a grid… I tried also parent.mouseX, no luck with that. Why is this happening? I thought mouseX/mouseY is always depending on the stage-dimension.

Answer

locrizak picture locrizak · May 26, 2011

have you tried:

function onEnterFrame(e:Event):void
{
  imagecontainer.image.x = stage.mouseX;
  imagecontainer.image.y = stage.mouseY;

}