0
votes

I'm running into some problems with making the movie clip so I can drag it about the stage. The scenario: the user clicks a button that spawns the movie clip to the stage, from there they can move the item around the stage - it's a draggable object. I can make it so the movieClip spawns, I can make it so it drags... but i can't make it do both, once I try to attach the drag function. Any pointers please? I'm new to as3! :-)

spawner_btn.addEventListener(MouseEvent.CLICK, spawnspinkjewel);

function spawnspinkjewel(event:MouseEvent):void
{
  var myChild:pink_jewel= new pink_jewel();
  stage.addChild(myChild)
myChild.x=300; 
    myChild.y=150;
} 
pink_jewel.addEventListener(MouseEvent.MOUSE_DOWN, pickupblack_pink_jewel);
pink_jewel.addEventListener(MouseEvent.MOUSE_UP, dropblack_pink_jewel);

function pickupblack_pink_jewel(event:MouseEvent):void {
event.target.startDrag(true);
}
function dropblack_pink_jewel(event:MouseEvent):void {
event.target.stopDrag();
}
1

1 Answers

0
votes

You added the listeners to the incorrect object.

Change this:

pink_jewel.addEventListener(MouseEvent.MOUSE_DOWN, pickupblack_pink_jewel);
pink_jewel.addEventListener(MouseEvent.MOUSE_UP, dropblack_pink_jewel);

To this:

myChild.addEventListener(MouseEvent.MOUSE_DOWN, pickupblack_pink_jewel);
myChild.addEventListener(MouseEvent.MOUSE_UP, dropblack_pink_jewel);