views:

14

answers:

1

I have a problem with the startDrag function I'm using in AS3. Right now I have a movie clip which is made up of 4 different layers. I export the movie clip, create and object of it, add in an event listener for mouse clicks that calls the startDrag function. However, instead of dragging the entire Movie Clip and all of its parts, it only grabs and drags one layer around, which breaks the different parts of the Movie Clip up.

public function HopperMouseDown(event:MouseEvent):void
{
   event.target.startDrag(true); //start dragging tile
   // mSoundManager.PlayTileUp(); //play tile up sfx
}

This is my function for the MouseClick event on the MovieClip. I initiate the startDrag event, but here it will not drag the entire Move Clip for some reason it only drags the different pieces inside the clip. Any help is appreciated.

A: 

You need to think about what is really going on here. First off, any mouse event will bubble but default. So when you are clicking on any of the 4 parts of the targeted object, you are receiving a MouseEvent from the individual nested MovieClips. There are a couple of ways to fix this behavior. First, you could set the "Hopper" MovieClip's mouseChildren property to false. This would prevent the individual parts from dispatching their own MouseEvents and instead only the MouseEvent dispatched by the "Hopper" would be received, in which case event.target would target correctly. Alternately, you could change event.target to event.currentTarget. The event.target property always references the event dispatcher (in your case, the individual piece) while event.currentTarget property refers to the node which is currently being checked for event listeners... which I would assume is the Hopper itself.

If any of that doesn't make sense then let me know and I can try to clarify.

sberry2A