一个另类的swapChildren的实现

简介:

一个另类的swapChildren的实现

 

I’m working on a project right now and swapChildren is just not working as expected. 

Looked around a bit, and I just decided to remove the two children and add copies of them instead:

var tmpThis:Canvas= EV.target as Canvas;
var tmpHighest:Canvas= highestPanel;
removeChild (highestPanel);
removeChild (EV.target as Canvas);
addChild(tmpHighest);
addChild(tmpThis);
 
------------------------------------------------------------------------------------------
 
 

原文出處: http://blog.csdn.net/tonywjd/archive/2008/01/11/2034737.aspx

在flex2中, 一個容器的子控制項相互重疊(如Canvas), 由z-order決定. swapChildren, swapChildrenAt用來交換兩個子控制項的z-order, 但有時會拋如下異常:

1 can1.swapChildrenAt(1, 0);

RangeError: Error #2006: The supplied index is out of bounds.

1 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:

1 container.removeChild(child1);
2 container.addChild(child1);

利用了每次添加的child總具有最大的z-order.

2). swap two children child1 and child2:

1 var i1:int = container.getChildIndex(child1);
2 var i2:int = container.getChildIndex(child2);
3 container.setChildIndex(child1, i2);
4 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

1 <HBox>
2     <Button/>
3     <Button/>
4 </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”

本文转自jiahuafu博客园博客,原文链接http://www.cnblogs.com/jiahuafu/archive/2010/04/29/1723549.html如需转载请自行联系原作者


jiahuafu

相关文章
|
Python
一日一技:你的代码是如何被炫技毁掉的
一日一技:你的代码是如何被炫技毁掉的
110 0
|
JSON 算法 fastjson
Fastjon2他来了,性能显著提升,还能再战十年
阿里官方给的定义是,FASTJSON是阿里巴巴的开源JSON解析库,它可以解析JSON格式的字符串,支持将Java Bean序列化为JSON字符串,也可以从JSON字符串反序列化到JavaBean。
571 1
|
运维 监控 架构师
【另类架构】之驾车感悟(下)
【另类架构】之驾车感悟(下)
133 0
【另类架构】之驾车感悟(下)
|
存储 算法 架构师
【另类架构】之驾车感悟(上)
【另类架构】之驾车感悟(上)
179 0
【另类架构】之驾车感悟(上)
|
新零售 数据挖掘 大数据
新零售的真相藏在哪?你需要知道这三点
2016年11月,马云在云栖大会提出“未来将没有电商,只有新零售”;两年后的今天,“新零售”已经遍地开花。从体感来看,智慧门店、快闪店正在更新人们的购物体验;数据来看,“新零售”带动线下消费成回暖趋势。
谈点杂的
人性弱点 1.男人好色 2.女人爱美 3.老人怕死 4.小孩贪玩 找到切入点,才能有好点子,但一定要用合法的手段
872 0
|
云计算
从“万金油”到“一招先”
本文讲的是从“万金油”到“一招先”,“我现在就像是急诊大夫,不论送进来什么病人,我都要在第一时间为其进行快速地诊疗,太累,而且已经力不从心。”这是经营着一家电子商务网站的林建斌发出的感慨,“有时我甚至感觉自己有些不务正业,更多的精力并没有放在如何提高销售额、提升利润上面,而是天天钻到机房里,与公司的诸多硬件设备斗争。
1280 0

相关实验场景

更多