0

我正在尝试制作书签之类的东西,我在舞台上有 1 个便条,当用户单击它时,它开始拖动,用户将它放到他们想要的地方。问题是我希望这些笔记被多次拖动..这是我的代码:

import flash.events.MouseEvent;

//notess is the instance name of the movie clip on the stage
notess.inputText.visible = false;
//delet is a delete button inside the movie clip,
notess.delet.visible = false;
//the class of the object i want to drag
var note:notes = new notes  ;

notess.addEventListener(MouseEvent.CLICK , newNote);

function newNote(e:MouseEvent):void
{
    for (var i:Number = 1; i<10; i++)
    {


        addChild(note);
                //inpuText is a text field in notess movie clip
        note.inputText.visible = false;
        note.x = mouseX;
        note.y = mouseY;        
        note.addEventListener( MouseEvent.MOUSE_DOWN , drag);
        note.addEventListener( MouseEvent.MOUSE_UP , drop);
        note.delet.addEventListener( MouseEvent.CLICK , delet);

    }
}

function drag(e:MouseEvent):void
{
note.startDrag();
}



function drop(e:MouseEvent):void
{
    e.currentTarget.stopDrag();
    note.inputText.visible = true;
    note.delet.visible = true;
}
function delet(e:MouseEvent):void
{
    removeChild(note);
}

任何帮助将不胜感激。

4

3 回答 3

0

如果您正在拖动多种类型的对象(例如注释和图像),您可以执行类似的操作,而不是对要实例化的对象类型进行硬编码。

function drop(e:MouseEvent):void{
   // Get a reference to the class of the dragged object
   var className:String = flash.utils.getQualifiedClassName(e.currentTarget);
   var TheClass:Class = flash.utils.getDefinitionByName(className) as Class;

   var scope:DisplayObjectContainer = this; // The Drop Target

   // Convert the position of the dragged clip to local coordinates
   var position:Point = scope.globalToLocal( DisplayObject(e.currentTarget).localToGlobal() );

   // Create a new instance of the dragged object
   var instance:DisplayObject = new TheClass();
   instance.x = position.x;
   instance.y = position.y;
   scope.addChild(instance);
}
于 2013-02-18T20:22:51.160 回答
0

您需要在拖放时创建笔记类的新实例,从拖动的笔记中复制位置和其他变量,将新笔记添加到舞台,并将拖动的笔记返回到其原始位置。

就像是:

function drop($e:MouseEvent):void
{
    $e.currentTarget.stopDrag();
    dropNote($e.currentTarget as Note);
}

var newNote:Note;

function dropNote($note:Note):void
{
    newNote = new Note();
    // Copy vars:
    newNote.x = $note.x;
    newNote.y = $note.y;
    // etc.
    // restore original note. 
    // You will need to store its original position before you begin dragging:
    $note.x = $note.originalX;
    $note.y = $note.orgiinalY;
    // etc.
    // Finally, add your new note to the stage:
    addChild(newNote);
}

...这确实是伪代码,因为我不知道您是否需要将新注释添加到列表中,或者将其链接到其原始注释。如果您使用Google ActionScript Drag Drop Duplicate,您会发现更多示例。

于 2012-08-23T08:58:04.033 回答
0

我认为您不是针对拖动功能中的拖动对象和对象实例化中的问题

for (var i:Number = 1; i<numberOfNodes; i++) {

        note = new note();
        addChild(note);
        ...
        ....
    }

 function drag(e:MouseEvent):void{
        (e.target).startDrag();
    }
于 2012-08-23T08:59:10.917 回答