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

Avatar of dgofman
dgofman
Flag of United States of America image

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));
Avatar of Karessa
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
Avatar of dgofman
dgofman
Flag of United States of America image

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

So great! Thank you so much.