Flex:确定组件是否正在显示 [英] Flex: Determine if a component is showing
问题描述
确定 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.
show
和 hide
事件触发可见性,这似乎适用于 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 不一定对 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."
我编写了一个示例应用程序来确认这是真的.你可以做的是在显示列表中检查 parent 上的 visible 是否为假.基本上可见"会给出误报,但不应给出误报.这是我整理的一个快速实用程序:
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屋!