swapChildren() makes objects persist past keyframe?

Karessa used Ask the Experts™
Objects stage1_btn through stage5_btn are only present on the first frame of my Flash file, but when I test the file they persist as long as this line executes:

this.swapChildren(t1, t2);

Does swapping the depth make the objects stick past the key frame they exist on?


var thisDepth:Number;
var child1:DisplayObject;
var child2:DisplayObject;

//handle events for buttons… about, home, portfolio are labels names in timeline
stage1_btn.addEventListener(MouseEvent.CLICK, clickSection);
stage2_btn.addEventListener(MouseEvent.CLICK, clickSection);
stage3_btn.addEventListener(MouseEvent.CLICK, clickSection);
stage4_btn.addEventListener(MouseEvent.CLICK, clickSection);
stage5_btn.addEventListener(MouseEvent.CLICK, clickSection);
stage1_btn.addEventListener(MouseEvent.MOUSE_OVER, rollSection);
stage2_btn.addEventListener(MouseEvent.MOUSE_OVER, rollSection);
stage3_btn.addEventListener(MouseEvent.MOUSE_OVER, rollSection);
stage4_btn.addEventListener(MouseEvent.MOUSE_OVER, rollSection);
stage5_btn.addEventListener(MouseEvent.MOUSE_OVER, rollSection);
function clickSection(evtObj:MouseEvent) {
	trace("The "+evtObj.target.name+" button was clicked!");
	//go to the section clicked on...


//On rollover make the objects swap depth.
function rollSection(evtObject:MouseEvent) {
	//set variables for the object and the object in the next depth
	var t1:DisplayObject=evtObject.target as DisplayObject;
	var t2:DisplayObject=getChildAt(this.numChildren-1) as DisplayObject;
	// give an error message if something is wrong with the objets
	if (t1==null||t2==null) {
		throw new Error("Invalid targets");
	//bring to the highest depth
	this.swapChildren(t1, t2);

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Can you explain more your problem?


Sure! Thanks.

Please see the file. On the first frame the pie graphic is big and in the center. You can click on any pie piece to go to the frame it relates to.

On subsequent frames the pie is supposed to be small and in the upper-right hand corner, but any pie pieces that have been rollod over and had the swapChildren() function applied now appear in the center and big instead of small and in the corner. Any pie pieces that have not been rolled over stay where they need to stay.
The file was partially fixed when I put

while (this.numChildren) {

in the clickSection function.


I found the answer to the problem on actionscript.org.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial