Search code examples
actionscript-3drag-and-dropdraggable

AS3 create a draggable movieclip inside an existing one at runtime


On the stage I have a button (new_btn) and a movieclip (workArea_mc), when I click the button I want to create a new movieclip inside the existing one.

I can do this, what I can't do is to make the new movieclip selectable and draggable.

This is how I create the new movieclip

new_btn.addEventListener(MouseEvent.CLICK, newMc);

function newMc (event:MouseEvent):void {
    var mc:MovieClip = new MovieClip();
    mc.graphics.beginFill(0xFF0000);
    mc.graphics.drawRect(0, 0, 660, 590);
    mc.graphics.endFill();
    mc.x = 15;
    mc.y = 15;
    workArea_mc.addChild(mc);
}

How do I make the new movieclip selectable and draggable?


Solution

  • First, you can add a event listener at the MovieClip what you would Drag, and in the listener, you can use the startDrag function in MovieClip Class.