2010-03-07 8 views
9

Estoy usando PopupManager en FB4 para mostrar un cuadro de diálogo personalizado.cómo mantener arrastrado TitleWindow dentro del límite de la aplicación Flex

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

Es posible arrastrar el TitleWindow aparecido y dejar ir de ella cuando su barra de título gris se encuentra fuera de los límites de la aplicación Flex rectángulo, y luego la ventana emergente no puede ser tomado de nuevo. También es posible arrastrar el TitleWindow hacia abajo para que se vuelva completamente invisible debajo del borde inferior del rectángulo de la aplicación Flex. Cuando los límites de la aplicación Flex son menores que la ventana completa del navegador y el usuario está trabajando rápidamente, aumentan las posibilidades de que esto ocurra. ¿Hay una configuración simple que evitará que esto suceda o el programador debe interceptar el comportamiento durante la operación de arrastre?

Gracias Tim

+0

Pregunta similar publicado aquí: http://stackoverflow.com/questions/1579117/how-to-prevent-a-component-from-being-dragged-out-of-the- stage-in-flex-3 – ggkmath

Respuesta

8

Hey, no hay un entorno sencillo para evitar que esto suceda de mi conocimiento. Todo lo que necesita hacer es mirarlo cada vez que se mueve y asegurarse de que se mantenga dentro de ciertos límites. A continuación, puede abstraer ese controlador de eventos en alguna clase de controlador si lo desea.

Aquí hay un ejemplo básico:

<?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> 

Espero que ayude, lanza

+0

Gracias por este útil ejemplo, Lance. – Tim

0

acaba de crear la clase y anulan evento move

SmartComponants paquete { importación 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); 
     } 
    } 

}

Cuestiones relacionadas