我在FB4中使用PopupManager来显示自定义对话框。
popwin = new TitleWindow(); popwin.addElement(myCustomDialog); PopUpManager.addPopUp(popwin,this,false); PopUpManager.centerPopUp(popwin);
可以拖动弹出的TitleWindow,当它的灰色标题栏位于Flex应用程序矩形的边界之外时放开它,然后弹出窗口无法再次抓取。也可以将TitleWindow向下拖动,使其在Flex应用程序矩形的下边缘下方完全不可见。当Flex应用程序界限小于完整浏览器窗口,并且用户正在快速工作时,这种情况发生的可能性会增加。是否有一个简单的设置可以防止这种情况发生,或者程序员是否必须在拖动操作期间拦截行为?
由于 添
答案 0 :(得分:8)
嘿,根据我的知识,没有一个简单的设置可以防止这种情况发生。您需要做的就是每次移动时都要观察它,并确保它保持在一定的范围内。然后,如果您愿意,可以将该事件处理程序抽象为某个Controller类。
这是一个基本的例子:
<?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>
希望有所帮助, 兰斯
答案 1 :(得分:0)
只需创建类并覆盖移动事件
包SmartComponants { import 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);
}
}
}