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了... 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值