2010-03-07 30 views
9

Tôi đang sử dụng PopupManager trong FB4 để hiển thị hộp thoại tùy chỉnh.làm thế nào để tiếp tục kéo TitleWindow trong ranh giới ứng dụng Flex

 
    popwin = new TitleWindow(); 
    popwin.addElement(myCustomDialog); 
    PopUpManager.addPopUp(popwin,this,false); 
    PopUpManager.centerPopUp(popwin); 

Có thể kéo TitleWindow popped lên và buông bỏ nó khi thanh tiêu đề màu xám của nó nằm ngoài giới hạn của hình chữ nhật ứng dụng Flex, và sau đó là cửa sổ bật lên không thể nắm lấy một lần nữa. Cũng có thể kéo TitleWindow xuống dưới để nó trở nên hoàn toàn vô hình bên dưới cạnh dưới cùng của hình chữ nhật ứng dụng Flex. Khi giới hạn ứng dụng Flex nhỏ hơn cửa sổ trình duyệt đầy đủ và người dùng đang hoạt động nhanh, cơ hội này sẽ tăng lên. Có một thiết lập đơn giản mà sẽ giữ điều này xảy ra, hoặc phải lập trình chặn các hành vi trong quá trình kéo?

Cảm ơn Tim

+0

câu hỏi tương tự được đăng ở đây: http://stackoverflow.com/questions/1579117/how-to-prevent-a-component-from-being-dragged-out-of-the- stage-in-flex-3 – ggkmath

Trả lời

8

Hey, không có một thiết lập đơn giản để ngăn chặn điều này xảy ra từ sự hiểu biết của tôi. Tất cả bạn cần làm là xem nó mỗi khi nó di chuyển và chắc chắn rằng nó vẫn nằm trong giới hạn nhất định. Sau đó bạn có thể tóm tắt trình xử lý sự kiện đó vào một số lớp Bộ điều khiển nếu bạn muốn.

Dưới đây là một ví dụ cơ bản:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    creationComplete="creationCompleteHandler()"> 

    <fx:Script> 
     <![CDATA[ 
      import flash.geom.Rectangle; 
      import mx.core.FlexGlobals; 
      import mx.core.UIComponent; 
      import mx.events.MoveEvent; 
      import mx.managers.PopUpManager; 
      import spark.components.TitleWindow; 

      protected function creationCompleteHandler():void 
      { 
       var window:TitleWindow = new TitleWindow(); 
       PopUpManager.addPopUp(window, this, false); 
       PopUpManager.centerPopUp(window); 
       window.addEventListener(MoveEvent.MOVE, window_moveHandler); 
      } 

      protected function window_moveHandler(event:MoveEvent):void 
      { 
       var window:UIComponent = event.currentTarget as UIComponent; 
       var application:UIComponent = FlexGlobals.topLevelApplication as UIComponent; 
       var bounds:Rectangle = new Rectangle(0, 0, application.width, application.height); 
       var windowBounds:Rectangle = window.getBounds(application); 
       var x:Number; 
       var y:Number; 
       if (windowBounds.left <= bounds.left) 
        x = bounds.left; 
       else if (windowBounds.right >= bounds.right) 
        x = bounds.right - window.width; 
       else 
        x = window.x; 
       if (windowBounds.top <= bounds.top) 
        y = bounds.top; 
       else if (windowBounds.bottom >= bounds.bottom) 
        y = bounds.bottom - window.height; 
       else 
        y = window.y; 
       window.move(x, y); 
      } 

     ]]> 
    </fx:Script> 

</s:Application> 

Hy vọng rằng sẽ giúp, Lance

+0

Cảm ơn ví dụ hữu ích này, Lance. – Tim

0

chỉ cần tạo lớp và ghi đè sự kiện di chuyển

gói SmartComponants { nhập khẩu spark.components.TitleWindow;

public class SmartTitleWindow extends TitleWindow 
{ 
    public function SmartTitleWindow() 
    { 
     super(); 
    } 
     private static const MIN_VISIBLE:int = 50; 

     public override function move(x:Number, y:Number):void 
     { 
      var maxX:Number = stage.stageWidth - MIN_VISIBLE; 
      var maxY:Number = stage.stageHeight - MIN_VISIBLE; 

      if (x < 0) 
       x = 0; 
      else if (x > maxX) 
       x = maxX; 

      if (y < 0) 
       y = 0; 
      else if (y > maxY) 
       y = maxY; 

      super.move(x, y); 
     } 
    } 

}

Các vấn đề liên quan