1

脚本问题是每个movieclip 向下和向上调度鼠标事件,但鼠标移动事件没有被某些movieclip 调度,这是一个意外的行为,而我已经跟踪了down 事件并且它成功地跟踪了每个对象

还推荐您对我的代码的反馈,谢谢。

    private function loadPurchasedClip(){
            var decorationItem:String;
            var lastItemIndex:uint = this.getChildIndex(tree1);
            var item:Sprite;

            for(var a in purchasedItems){

                for(var b in purchasedItems[a]){

                if(purchasedItems[a][b].item=='shed'){
                    item = new shed();
                } else {

                    var ClassDefinition:Class = loadedDecorationItem.purchaseItem(purchasedItems[a][b].item) as Class;


                    item = new ClassDefinition();

                }
                item.x = purchasedItems[a][b].posX;
                item.y = purchasedItems[a][b].posY;


                item.addEventListener(MouseEvent.MOUSE_DOWN,function(e:MouseEvent){
                        Mouse.cursor = "hand";
                        e.target.startDrag(false);

                        dusbin.visible = true;
                    item.addEventListener(MouseEvent.MOUSE_MOVE,trashMe);
                });

                item.addEventListener(MouseEvent.MOUSE_UP,function(e:MouseEvent){

                    Mouse.cursor = "auto";
                    e.target.stopDrag();
                    externalPhpCall(e);
                    dusbin.visible = false;
                    if(trashClip){
                        removeChild(trashClip);
                        trashClip = null;
                    }
                });
                item.mouseChildren = false;


                // if item is fence or flowers then move them behind the tree
                if(
                    String(purchasedItems[a][b].item).indexOf('fence')!=-1
                    ||
                    String(purchasedItems[a][b].item).indexOf('flower')!=-1
                ){
                    addChildAt(item,lastItemIndex);

                    lastItemIndex++;
                } else {
                    addChildAt(item,this.numChildren-2);
                }

                purchasedNameAr[getChildIndex(item)] = purchasedItems[a][b].item;

            }

        }
4

2 回答 2

1

不能确定,但​​我认为您可能希望剪辑继续调度 MouseEvent.MOUSE_MOVE 事件,即使鼠标离开剪辑 - 这不会发生,只有当本地鼠标指针共同时 -纵坐标(即 yourClip.mouseX/mouseY)与将触发的剪辑本身的图形相交 - 即使在拖动剪辑时,也不能保证它会调度 MOVE 事件。

假设您的剪辑都在根目录上,这意味着您可以访问“舞台” - 您可以这样做:

代替:

item.addEventListener(MouseEvent.MOUSE_MOVE,mouseMove);

和:

stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMove);

...但是您应该记住在必要时删除该事件(再次使用阶段,以防鼠标未在剪辑上释放):

 stage.addEventListener(MouseEvent.MOUSE_UP,endMove);


//Don't use anon function as won't have stage reference:

function endMove(e:MouseEvent):void {
        //The rest of your code, then:
        stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMove);
    }
于 2013-03-27T13:46:08.557 回答
0
        private  function loadPurchasedClip(){
        var decorationItem:String;
        var lastItemIndex:uint = this.getChildIndex(tree1);
        var item:Sprite;
        var Move:Boolean

        for(var a in purchasedItems){

            for(var b in purchasedItems[a]){

            if(purchasedItems[a][b].item=='shed'){
                item = new shed();
            } else {

                var ClassDefinition:Class = loadedDecorationItem.purchaseItem(purchasedItems[a][b].item) as Class;

                item = new ClassDefinition();

            }
            item.x = purchasedItems[a][b].posX;
            item.y = purchasedItems[a][b].posY;
            item.addEventListener(e:Event.ENTER_FRAME, onEnterFrame);
            item.addEventListener(MouseEvent.MOUSE_DOWN,function(e:MouseEvent){
                    Mouse.cursor = "hand";
                    e.target.startDrag(false);
                    Move = true
                    dusbin.visible = true;

            });

            item.addEventListener(MouseEvent.MOUSE_UP,function(e:MouseEvent){

                Mouse.cursor = "auto";
                e.target.stopDrag();
                externalPhpCall(e);
                dusbin.visible = false;
                if(trashClip){
                    removeChild(trashClip);
                    trashClip = null;
                }
            });
            item.mouseChildren = false;

            // if item is fence or flowers then move them behind the tree
            if(
                String(purchasedItems[a][b].item).indexOf('fence')!=-1
                ||
                String(purchasedItems[a][b].item).indexOf('flower')!=-1
            ){
                addChildAt(item,lastItemIndex);

                lastItemIndex++;
            } else {
                addChildAt(item,this.numChildren-2);
            }

            purchasedNameAr[getChildIndex(item)] = purchasedItems[a][b].item;

        }
        function onEnterFrame(e:Event):void{
         if(Move){
        // what ever here

        {

    }
于 2013-03-27T13:11:52.480 回答