Flex:确定组件是否显示 [英] Flex: Determine if a component is showing
问题描述
确定Flex / Flash中的组件是否显示在用户屏幕上的最佳方式是什么?我正在寻找类似于Java的 Component.isShowing()方法。
显示
和隐藏
事件触发可见性,这似乎适用于ViewStack组件的第一个后代,但不会进一步向下显示树。
UIComponent.visible不一定对于visible = false的对象的子句有效。在文件中:
在任一情况下,对象的子对象都不会发出显示或隐藏事件,除非该对象已经专门写了一个实现。 / p>
我写了一个证明这一点的示例应用程序。您可以做的是走上显示列表,检查父母是否可视。基本上可见给出假阳性,但不应该给予假阴性。这是一个快速实用程序,我放在一起:
包
{
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是Application))
return checkDisplayObjectVisible(obj.parent);
else
返回true;
}
}
}
我没有做任何事对此不仅仅是微不足道的考验,而应该让你开始。
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.
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 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屋!