An alternative implementation of swapchildren

Source: Internet
Author: User

An alternative implementation of 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);
 
------------------------------------------------------------------------------------------
 

Original article: http://blog.csdn.net/tonywjd/archive/2008/01/11/2034737.aspx

In flex2, the sub-controls of a container are mutually duplicated (such as canvas), determined by Z-order. swapchildren and swapchildrenat are used to subscribe the Z-order of two sub-controllers. However, the following conditions may occur:

View SourcePrint?
1 can1.swapChildrenAt(1, 0);

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

View SourcePrint?
1 can1.swapChildren(clus1, t1);

Argumenterror: Error #2025: The supplied displayobject must be a child of the caller.

The typical scenario I have encountered is that when the sub-controller extends resize beyond the canvas, the following two methods can be used to replace the actual control Z-order:

1). Put Child1 at the most Z-order:

View SourcePrint?
1 container.removeChild(child1);
2 container.addChild(child1);

The maximum Z-order is always used for each added child.

2). Swap two children Child1 and child2:

View SourcePrint?
1 var i1:int = container.getChildIndex(child1);
2 var i2:int = container.getChildIndex(child2);
3 container.setChildIndex(child1, i2);
4 container.setChildIndex(child2, i1);

The cause description can be found in a 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

View SourcePrint?
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.

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.