本文主要是介绍Flex2 z-order问题解决,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在flex2中, 一个容器的子控件相互重叠(如Canvas), 由z-order决定. swapChildren, swapChildrenAt用来交换两个子控件的z-order, 但有时会抛如下异常:
can1.swapChildrenAt(1, 0);
RangeError: Error #2006: The supplied index is out of bounds.
can1.swapChildren(clus1, t1);
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
我碰到这种异常的典型情况是当子控件Resize到超出Canvas之外时. 不过可以用如下两种方式替代实现控制z-order:
1). Put child1 at the most z-order:
container.removeChild(child1);
container.addChild(child1);
利用了每次添加的child总具有最大的z-order.
2). swap two children child1 and child2:
var i1:int = container.getChildIndex(child1);
var i2:int = container.getChildIndex(child2);
container.setChildIndex(child1, i2);
container.setChildIndex(child2, i1);
具体原因描述可在一个mail list找到: (http://www.mail-archive.com/flexcoders@yahoogroups.com/msg61112.html):
"You say your container is a DisplayObjectContainer. Is it also a Flex Container
such as Canvas or VBox? If so, there is a bug with using swapChildrenAt() and
maybe with swapChildren() as well. Try using removeChildAt() and addChildAt()
instead.
A Flex Container does tricky stuff with child indexes and overrides child
management APIs such as numChildren, addChildAt(), removeChildAt(), etc.,
because there are two kinds of children -- content children and non-content
children. If you write
<HBox>
<Button/>
<Button/>
</HBox>
there are only two content children but, if the HBox has a background or
scrollbars, there can be additional non-children children.
I think what happened is that the swapChildren() and swapChildrenAt() methods
got added to DisplayObjectContainer in Player 9, and the Flex framework is not
yet supporting them properly in the Container class.
- Gordon"
顺便提一下:
1). PopUpManager也可改变重叠状态, 但它是作为弹出窗口, 改变了原先的层次(父子)关系, 所在坐标轴等.
2). debug模式下用trace(string)可在控制台打印调试信息.
3). Canvas有个clipContent可允许子控件显示超出Canvas的范围(http://www.judahfrangipane.com/blog/?p=101).
4). horizontalScrollPolicy="off" verticalScrollPolicy="off"可以去掉滚动条.
5). 没想到又写Flex了...
这篇关于Flex2 z-order问题解决的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!