2013-03-27 76 views
1

腳本問題是,每個movieclip調度向下和向上鼠標事件,但鼠標移動事件不是由某些影片剪輯調度,這是一個意外的行爲,而我跟蹤了down事件,並且它成功跟蹤每個對象ActionScript 3鼠標移動事件不發送

也建議您對我的代碼的反饋,謝謝。

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; 

      } 

     } 
+0

你有你的鼠標MouseMove函數內的事件? – joshua 2013-03-27 13:07:13

+1

嘗試在註冊鼠標移動事件時使用e.target not item。 – 2013-03-27 13:09:28

+0

感謝Lukasz'Severiaan'Grela – justnajm 2013-03-28 11:37:08

回答

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 

     { 

    } 
+0

感謝朋友,但e:事件沒有任何屬性,比如e.stageX – justnajm 2013-03-27 17:04:27

+0

顯然你可能需要寫這個更好,但它確實工作,因爲我使用3d應用程序的這種方法 – joshua 2013-03-28 02:39:55

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); 
    } 
+0

Thanks @ MickMalone1983但在我的情況下,我正在移動剪輯,而鼠標停下來,並停止使用鼠標移動。移動時我需要剪輯的x和y值。但沒有運氣:( – justnajm 2013-03-27 17:01:27

+0

您可以使用mouseMove函數來獲取這些,它會發送一個MouseEvent,您可以從中獲取e.target.x/y – MickMalone1983 2013-03-27 17:42:47

相關問題