Flex 弹出窗口的定位/滚动问题 [英] Positioning / Scrolling problem with Flex popup

查看:25
本文介绍了Flex 弹出窗口的定位/滚动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PopUpManager 解决在 Flex 中定位时遇到的特定问题.基本上我想创建一个弹出窗口,它会随着父容器滚动 - 这是必要的,因为父容器很大,而且如果用户的浏览器窗口不够大(大多数情况下都是这种情况) -他们将不得不使用容器的滚动条向下滚动.问题是弹出窗口是相对于另一个组件定位的,它需要停留在那个组件旁边.

I'm trying to work out a specific problem I'm having with positioning in Flex using the PopUpManager. Basically I'm wanting to create a popup which will scroll with the parent container - this is necessary because the parent container is large and if the user's browser window isn't large enough (this will be the case the majority of the time) - they will have to use the scrollbar of the container to scroll down. The problem is that the popup is positioned relative to another component, and it needs to stay by that component.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

  <mx:Script>
    <![CDATA[
      import mx.core.UITextField;
      import mx.containers.TitleWindow;
      import mx.managers.PopUpManager;

      private function clickeroo(event:MouseEvent):void {
        var popup:TitleWindow = new TitleWindow();
        popup.width = 250;
        popup.height = 300;

        popup.title = "Example";
        var tf:UITextField = new UITextField();
        tf.wordWrap = true;
        tf.width = popup.width - 30;
        tf.text = "This window stays put and doesn't scroll when the hbox is scrolled (even with using the hbox as parent in the addPopUp method), I need the popup to be local to the HBox.";
        popup.addChild(tf);

        PopUpManager.addPopUp(popup, hbox, false);
        PopUpManager.centerPopUp(popup);
      }
    ]]>
  </mx:Script>

  <mx:HBox width="100%" height="2000" id="hbox">
    <mx:Button label="Click Me" click="clickeroo(event)"/>
  </mx:HBox>

</mx:Application>

谁能给我任何正确方向的指示?谢谢.

Could anyone give me any pointers in the right direction? Thanks.

推荐答案

PopUpManager 添加了另一个独立于原始应用程序的层.
因此,如果您希望它相对于第一层,您可能不想使用 PopUpManager.您可以在 Canvas 之上使用 TitleWindow.

PopUpManager adds another layer which is independent of the original Application.
So you probably don't want to use PopUpManager if you want it to stay relative to the first layer. You can just use a TitleWindow on top of a Canvas.

你可能有过这样的经历:

You might have had this:

<mx:Application creationComplete="createPopup()">
    <mx:Script>
        <![CDATA[
            public var popupPanel:TitleWindow = new TitleWindow();

            private function createPopup():void
            {
                PopUpManager.addPopUp(popupPanel, myApp, true);
                PopUpManager.centerPopUp(popupPanel);
            }
        ]]>
    </mx:Script>

    <mx:Canvas id="myApp" width="100%" height="2000" />
</mx:Application>

但是你会想要尝试这样的事情:

But instead you will want to try something like this:

<mx:Application creationComplete="createPopup()">
    <mx:Script>
        <![CDATA[
            public var popupPanel:TitleWindow = new TitleWindow();

            private function createPopup():void
            {
                // Assuming MyApplication extends Canvas
                (myApp as Canvas).addChild(popupPanel);
                popupPanel.x = myApp.width/2;
                popupPanel.y = myApp.height/2;
            }
        ]]>
    </mx:Script>

    <mx:Canvas id="myApp" width="100%" height="2000" />
</mx:Application>

您需要自己决定什么是最适合您的应用的 x,y 值.

You will need to decide for yourself what the best x,y values are for your application.

如果您还想让这个 TitleWindow 可拖动/移动,那么您可以使用 Sprite.startDrag() 函数来实现.

If you also want to make this TitleWindow draggable/moveable, then you can do so with the Sprite.startDrag() function.

让我知道这是否有帮助!

Let me know if this helps!

这篇关于Flex 弹出窗口的定位/滚动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆