1

I have this actionscript code. What i'm trying to do is to trigger a mouse event on imgSprite, which is a child element of imageContainer. I was expecting it to triger it on the mouse coordinates on imgSprite, but instead it uses the last loaded instance of imgSprite. To get a bigger picture, i'm trying to switch two puzzle pieces so when i drop one, the one underneath is picked up imediately. I do this by removing the upper one (selectedImage) and dispatching a mouse_down event which should be picked up by event listener (pointing to imgSprite) and directed to mouse_down function.

function mouse_Down(e:MouseEvent):void 
    {
        dropSelectedImage();
        if(selectedImage) imageContainer.addChild(selectedImage); 
        imageContainer.removeChild(e.currentTarget as Sprite); 
        imageContainer.addChild(e.currentTarget as Sprite); 
        selectedImage = e.currentTarget as Sprite;
        selectedImage.startDrag();
    }
    function mouse_Up(e:MouseEvent):void{
        dropSelectedImage();
        imageContainer.removeChild(selectedImage); 
        imgSprite.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN,true,true));
    }
monolith
  • 1,606
  • 1
  • 12
  • 21

1 Answers1

0

turn bubbling on, and debug the difference between even.target and event.currentTarget.

csomakk
  • 5,369
  • 1
  • 29
  • 34