troubleshooting Question

swapChildren() makes objects persist past keyframe?

Avatar of Karessa
Karessa asked on
Adobe Flash
4 Comments1 Solution375 ViewsLast Modified:
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);
}
ASKER CERTIFIED SOLUTION
Karessa

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros