0
function Drag(event:MouseEvent):void {
    if ((event.target.parent == InventoryMenu) && (event.target is item)) {
        var picked:item = item(event.target);
        stage.addEventListener(MouseEvent.MOUSE_UP, Drop);
        InventoryArrowDown.addEventListener(MouseEvent.MOUSE_OVER, InventoryNav("down"));
        InventoryArrowUp.addEventListener(MouseEvent.MOUSE_OVER, InventoryNav("up"));

        function Drop(event:MouseEvent):void {
            if ((event.target.parent == InventoryMenu) && (event.target is item)) {
                var dropped:item = item(event.target);          
                if ((event.target is item) && (event.target.parent == InventoryMenu)) {
                    if (picked.itemdata("workswith") == dropped.name) {
                        var itemname:item = item(FetchResult(picked, dropped));
                        itemname.addChild(itemname.itemdata("filename"));
                        InventoryMenu.removeChild(picked);
                        InventoryMenu.removeChild(dropped);
                        InventoryMenu.addChild(itemname);
                        InventoryUpdate();
                    } else if (picked.name != dropped.name) {
                        trace("No son compatibles");
                    }
                    stage.removeEventListener(MouseEvent.MOUSE_UP, Drop);
                    InventoryArrowDown.removeEventListener(MouseEvent.MOUSE_OVER, InventoryNav("down"));
                    InventoryArrowUp.removeEventListener(MouseEvent.MOUSE_OVER, InventoryNav("up"));
                }
            }
        }
    }
}

由于某种原因,InventoryArrowDown 和 InventoryArrowUp 上的 removeEventListener 不起作用。我相当确定路由是正确的,因为它是从 addEventListener 直接复制粘贴的,并且它不使用任何变量。

任何线索有什么问题?

4

1 回答 1

0

很难在没有看到代码的情况下帮助您,InventoryNav但问题可能是您应该在测试之前删除事件侦听器。

此外,您应该编写两个不同的处理程序,而不是像您一样使用一个并传递参数。

这是您的代码的修改版本,可能会有所帮助:

private function drag(event:MouseEvent):void {
    if ((event.target.parent == inventoryMenu) && (event.target is Item)) {
        var picked:Item = Item(event.target);
        stage.addEventListener(MouseEvent.MOUSE_UP, drop);
        inventoryArrowDown.addEventListener(MouseEvent.MOUSE_OVER, inventoryNavDown);
        inventoryArrowUp.addEventListener(MouseEvent.MOUSE_OVER, inventoryNavUp);
    }
}

private function drop(event:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_UP, drop);
    inventoryArrowDown.removeEventListener(MouseEvent.MOUSE_OVER, inventoryNavDown);
    inventoryArrowUp.removeEventListener(MouseEvent.MOUSE_OVER, inventoryNavUp);

    if ((event.target.parent == inventoryMenu) && (event.target is Item)) {
        var dropped:Item = Item(event.target);          
        if ((event.target is Item) && (event.target.parent == inventoryMenu)) {
            if (picked.itemdata("workswith") == dropped.name) {
                var itemname:Item = Item(fetchResult(picked, dropped));
                itemname.addChild(itemname.itemdata("filename"));
                inventoryMenu.removeChild(picked);
                inventoryMenu.removeChild(dropped);
                inventoryMenu.addChild(itemname);
                inventoryUpdate();
            } else if (picked.name != dropped.name) {
                trace("No compatible sons");
            }
        }
    }
}
于 2013-05-10T00:57:04.267 回答