2010-11-22 68 views
1

我有一個畫布,上面畫矩形等形狀。當我使用自定義鼠標向下/鼠標移動處理程序移動形狀時,形狀可以超出父界。如何防止在Flex/Flash中的父容器外面拖動?

我檢查,如果孩子在外面父母的束縛將其歸:當我去左邊或頂部邊界之外

var bounds:Rectangle = this.getBounds(this.parent); 
    var p:Point; 

    if (bounds.x <0) { 
    p = new Point(0,0); 
    p.offset(-bounds.x,0); 
    } 
    if (bounds.y <0) { 
    if (!p) p = new Point(0,0); 
    p.offset(0,-bounds.y); 
    } 
    if (bounds.y+bounds.height > this.parent.height) { 
    if (!p) p = new Point(0,0); 
    p.offset(0,-bounds.y-height+this.parent.height); 
    } 
    if (bounds.x+bounds.width > this.parent.width) { 
    if (!p) p = new Point(0,0); 
    p.offset(-bounds.x-width+this.parent.width,0); 
    } 
    if (p) { 
    trace("invoking snapInside ", p); 
      snapInside(p); 

的snapInside方法被調用。但是當孩子拖到右邊或底部邊界之外時,我發現Flex/Flash運行時會自動擴展父代的高度和寬度。所以說父母的大小最初是800x600,如果孩子Y的邊界超過800像20像素,我發現this.parent.height自動調整大小爲flex到820!

當孩子超出父母的原始界限時,我該如何防止父母調整大小?

+0

爲什麼不startDrag(false,new Rectangle(... bounds ...)) – alxx 2010-11-23 07:24:39

回答

1

創建父對象時,將邊界保存到函數外部的變量,以便稍後調用存儲的大小。如果你不斷檢查你的函數中的邊界,那麼它當然會隨着父對象的變化而改變。或者在mouseDown上設置邊界,但不要拖動,以便在拖動對象碰到邊緣之前有一個更新的邊界。

+0

這就是我最終做的。看到你在我的帖子後建議相同。不管怎麼說,多謝拉。 – TBD 2010-11-23 18:12:23

相關問題