Avatar of Karessa
Karessa
 asked on

swapChildren() makes objects persist past keyframe?

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?

stop();

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...
	gotoAndStop(evtObj.target.name);

}

//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

Adobe Flash

Avatar of undefined
Last Comment
Karessa

8/22/2022 - Mon
dgofman

Can you explain more your problem?
Karessa

ASKER
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.
StaffDevWheel5-22-12.fla
ASKER CERTIFIED SOLUTION
Karessa

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Karessa

ASKER
I found the answer to the problem on actionscript.org.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck