Avatar of Karessa
Karessa
 asked on

Swap Depths in AS3

The code in the function  rollSection(evtObject:MouseEvent)  is intended to make the object in question come to the highest depth, but it doesn't work! Is it because the objects are buttons? If so, can I cast them as movie clips?


stop();

var thisDepth:Number;

//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);
}

function rollSection(evtObject:MouseEvent) {
	trace("The "+evtObject.target.name+" button was rolled!");
	//bring to the highest depth
	this.setChildIndex(evtObject.target.name,this.numChildren-1);
}

Open in new window

Adobe Flash

Avatar of undefined
Last Comment
Karessa

8/22/2022 - Mon
dgofman

Did you try to use swapChildren?

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#swapChildren%28%29

Try



this.swapChildren(evtObject.target,  getChildAt(this.numChildren-1));
Karessa

ASKER
Thanks for your help!

Hm, when I use that line I get

#1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject

Do I need to cast it as a movie clip? I tried:

MovieClip(this).swapChildren(evtObject.target,  getChildAt(this.numChildren-1));

But that was no good.
ASKER CERTIFIED SOLUTION
dgofman

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
So great! Thank you so much.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck