一个另类的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

相关文章
|
2月前
|
前端开发 JavaScript 调度
小型的编程项目有哪些值得推荐?这本神书写了 22 个,个个了不得
小型的编程项目有哪些值得推荐?这本神书写了 22 个,个个了不得
19 1
|
2月前
|
JavaScript 前端开发 Java
程序员在七夕如何用各大编程语言写浪漫情书呢?
程序员在七夕如何用各大编程语言写浪漫情书呢?
20 0
|
10月前
|
算法 程序员 数据安全/隐私保护
2022 年终总结|怎样写出一篇还不错的文章
2022 年终总结|怎样写出一篇还不错的文章
54 0
|
11月前
|
前端开发 JavaScript 程序员
程序员祝福圣诞快乐的方式(内涵完整代码)
程序员祝福圣诞快乐的方式(内涵完整代码)
137 0
|
程序员 Android开发 iOS开发
程序员五一修图小贴士
程序员五一修图小贴士
121 0
程序员五一修图小贴士
|
数据安全/隐私保护
推荐5个神仙软件,个个让你爱不释手
最近陆陆续续收到好多小伙伴的咨询,这边也是抓紧时间整理出几个好用的软件,希望可以帮到大家。
156 0
|
存储 算法 架构师
【另类架构】之驾车感悟(上)
【另类架构】之驾车感悟(上)
148 0
【另类架构】之驾车感悟(上)
|
运维 监控 架构师
【另类架构】之驾车感悟(下)
【另类架构】之驾车感悟(下)
【另类架构】之驾车感悟(下)
|
IDE 网络协议 安全
程序员必定会爱上的10款软件
程序员必定会爱上的10款软件
194 0
程序员必定会爱上的10款软件
|
机器学习/深度学习 人工智能 移动开发
从需求生成代码?D2 最具争议的分享,你值得来瞄一眼
专访狼叔和卓风,聊聊他们这个最受争议也备受期待的话题背后的故事。
从需求生成代码?D2 最具争议的分享,你值得来瞄一眼

相关实验场景

更多