Flex:确定组件是否显示 [英] Flex: Determine if a component is showing

查看:23
本文介绍了Flex:确定组件是否显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定 Flex/Flash 中的组件是否显示在用户屏幕上的最佳方法是什么?我正在寻找类似于 Java 的 Component.isShowing() 方法.

What is the best way to determine if a component in Flex/Flash is showing on the user's screen? I'm looking for an analog to Java's Component.isShowing() method.

showhide 事件触发可见性,这似乎适用于 ViewStack 组件的第一个后代,但不适用于显示树.

The show and hide events fire for visibility, and this seems to work for the first descendant of a ViewStack component, but not further down the display tree.

推荐答案

UIComponent.visible 不一定对可见=false 的对象的子级有效.来自文档:

UIComponent.visible is not necessarily valid for children of an object where visible=false. From the docs:

在任何一种情况下,对象的子对象都不会发出显示或隐藏事件,除非对象专门编写了一个实现来这样做."

"In either case the children of the object will not emit a show or hide event unless the object has specifically written an implementation to do so."

我编写了一个示例应用程序来证实这是真的.您可以做的是在显示列表中检查可见性是否在父项上为假.基本上可见"会给出误报,但不应该给出误报.这是我整理的一个快速实用程序:

I wrote a sample application that confirms this to be true. What you can do is walk up the display list checking for visible to be false on a parent. Basically "visible" gives false positives but shouldn't give false negatives. Here is a quick utility I put together:

package
{
    import flash.display.DisplayObject;

    import mx.core.Application;

    public class VisibilityUtils
    {
        public static function isDisplayObjectVisible(obj : DisplayObject) : Boolean {
            if (!obj.visible) return false;
            return checkDisplayObjectVisible(obj);
        }

        private static function checkDisplayObjectVisible(obj : DisplayObject) : Boolean {
            if (!obj.parent.visible) return false;
            if (obj.parent != null && !(obj.parent is Application))
                return checkDisplayObjectVisible(obj.parent);
            else
                return true;
        }
    }
}

除了简单的测试之外,我还没有做过任何其他事情,但它应该可以帮助您入门.

I haven't done anything more than trivial tests on this but it should get you started.

这篇关于Flex:确定组件是否显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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