【问题标题】:How to know if a popup is already showing up on the screen in flex如何知道一个弹出窗口是否已经出现在 flex 的屏幕上
【发布时间】:2011-07-11 13:45:52
【问题描述】:

我需要知道一个弹出窗口(这是一个单例标题窗口,因此只会被初始化一次)是否已经显示在屏幕上,如果没有,那么我将调用一个函数来显示它,否则做其他事情.

我试过findPopup.focusEnabled //findPopup是popup的titlewindow类

但无论弹出窗口当前是否显示在屏幕上,它总是正确的。

谢谢。

【问题讨论】:

    标签: actionscript-3 apache-flex actionscript flex3


    【解决方案1】:

    使用isPopUp

    由 PopUpManager 设置为 true 以指示该组件已 弹出来。

    【讨论】:

      【解决方案2】:

      在屏幕上渲染的所有对象都有一个root:DisplayObject 属性。如果将其从屏幕上移除,则root 将为空。如果您担心弹出窗口是否在其他所有内容之前,请使用popUpObj.parent.setChildIndex(popUpObj, popUpObj.parent.numChildren - 1) 来确保它(更多内容见下文)。您将需要遍历所有父级,直到到达 root 本身。 (用PopUpManager,我相信MovieClip是直接加到root的,所以应该只有一次,不过暂时不记得了)

      其他一切都很明显:

      • alpha = 1?
      • 可见 = 真?
      • 是宽度 > 5
      • 身高>5
      • ...我可以继续,但我认为这个想法很清楚。

      关于测试被遮挡物体的可见性:

      老实说,这在root 上是最容易做到的。

      var firstParent:DisplayObjectContainer = /* 
                                                  find the ancestor which is on 
                                                  the root. You may need to look up 
                                                  "path to root AS3"
                                               */
      var num:int = root.numChildren;
      //iterate backwards to exclude things below the target clip.
      for( var i:int = num - 1; i >= 0; i-- )
      {
           var kid:DisplayObject = root.getChildAt( i );
           if( kid == firstParent ) break; // no sense in continuing.
           if( firstParent.hitTestObject( kid ) )
           {
               // kid at least partially obscures the pop-up. Do something with it.
           }
      }
      

      【讨论】:

        【解决方案3】:

        您可以使用 if 块检查对象是否存在

        if(findPopup)
        findPopUp.visible=true;
        

        假设您关闭了可见性以隐藏窗口。如果需要,您当然可以销毁该对象并重新创建它。在这种情况下,您不需要 if 块,因为它将从头开始重建。

        您仍然可以使用 if 逻辑来确定您的代码中是否有某些东西已经创建了您的弹出对象。也许另一个类会在幕后做这件事,所以基本的想法是保证这样的对象存在与否。

        【讨论】:

        • 不,它是一个单例类,我通过删除弹出管理器的弹出功能来关闭它。可见性标志一旦设置始终保持打开。但是,我确实创建了一个公共属性并在显示事件时将其设置为打开,并在关闭弹出窗口时将其关闭。
        【解决方案4】:

        [编辑:]

        不知道您正在使用 PopUpManager。请使用 Ranhiru Cooray 的回答。

        提醒一下,PopUpManager 有自己的方法可以在所有其他对象前面放置一个弹出窗口:bringToFront(popup)

        [/编辑]

        您是否要确定弹出窗口是否已添加到舞台上,或者它是否仍然在屏幕上可见并且没有隐藏在其他显示对象后面?

        如果是第一个,你可以通过搜索找到(flex 3)

        // popUpContainer is the object containing the pop up
        if (popUpContainer.contains(FindPopup.getInstance()))
        {
              // The popup was added to stage
        }
        else
        {
              popUpContainer.addChild(FindPopup.getInstance());
        }
        

        如果是第二个,您可以通过将其添加到应用程序根目录并确保它具有最高索引来确保它是可见的。但很难测试它是否真的显示在屏幕上,因为它可能有 40% 或 60% 隐藏在其他对象后面。

        // Placing the pop up on top of other display objects in the application root
        this.setChildIndex(FindPopup.getInstance(), this.numChildren - 1);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-05-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-06-29
          相关资源
          最近更新 更多