Link to home
Start Free TrialLog in
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

Avatar of dgofman
dgofman
Flag of United States of America image

Can you explain more your problem?
Avatar of Karessa
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
Avatar of Karessa
Karessa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Karessa

ASKER

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