ActionScript 3鼠标移动事件未调度

时间:2013-03-27 13:02:32

标签: actionscript-3 mouseevent

脚本问题是每个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;

            }

        }

2 个答案:

答案 0 :(得分: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);
    }

答案 1 :(得分: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

        {

    }