Flash CS4 如何设置对象拖动碰撞的变量?

Flash CS4 How do you set variable to the Object Dragging Collison?

我正在为我的计算机科学做一个游戏 class 我正在处理库存,将一个项目拖入其中。我不知道如何将项目设置为用户单击拖动的任何内容。

目前我将其硬编码到他们正在拖动的项目中,但将来我想要更多项目,因此为他们正在拖动的项目设置一个变量会使它完美地工作,但我不知道这样做叫什么。

这是我的库存项目拖动代码

function dragItem (event:MouseEvent):void
{
    knife_loot.startDrag();
}

function dropItem (event:MouseEvent):void
{
    knife_loot.stopDrag();

    if ((knife_loot.hitTestObject(inv_game)) && (inv_game.visible == true))
    {
        trace("Item dropped in inventory")
        trace("")

        knife_loot.x = 80
        knife_loot.y = 120
    }
}

// end of dragging and dropping items

您可以从:

开始
// List the items you want to drag.
var aList:Array = [knife_loot, spoon_loot, fork_loot];

// InteractiveObject is superclass for SimpleButton, Sprite and MovieClip.
// If you're sure what they all are then just use their class instead.
for each (var anItem:InteractiveObject in aList)
{
    // Subscribe them all for dragging.
    anItem.addEventListener(MouseEvent.MOUSE_DOWN, onDrag);
}

public var draggedItem:InteractiveObject;

function onDrag(e:MouseEvent):void
{
    // Use e.currentTarget because original MouseEvent e.target
    // could be something from deep inside of top object e.currentTarget.
    draggedItem = e.currentTarget as InteractiveObject;
    draggedItem.startDrag();

    // Let's hook drop events.
    stage.addEventListener(Event.MOUSE_LEAVE, onDrop);
    stage.addEventListener(MouseEvent.MOUSE_UP, onDrop);
}

function onDrop(e:Event):void
{
    // Unhook drop events.
    stage.removeEventListener(Event.MOUSE_LEAVE, onDrop);
    stage.removeEventListener(MouseEvent.MOUSE_UP, onDrop);

    // Drop the item.
    draggedItem.stopDrag();

    if ((draggedItem.hitTestObject(inv_game)) && (inv_game.visible == true))
    {
        trace("Item", draggedItem.name, "was dropped to inventory.");
        trace("");

        draggedItem.x = 80;
        draggedItem.y = 120;
    }

    // Forget the item.
    draggedItem = null;
}