Hello!
I want to swap the depths of some movieclips that are inside another movieclip in AS3, as you could do in AS2. I've found out how to do that:
In this instance:
the overall movieclip 'container' is called: layers_mc
three movieclips on different layers within that are called:
- bio_mc_content
- current_mc_content
- news_mc_content
when I click on different movieclips (which act as buttons I suppose), on the main stage and outside of the "layers_mc", I want the corresponding movieclip in the "layers_mc" to rise to the top of the pile and therefore be the visible one.
the respective names of these "button" movieclips are
- bio_mc
- current_mc
- news_mc
I've managed to make this work if I specify the exact name of the layers_mc.movieclip I want shifting to the top, but I want to get my code to be more re-usable, so I can do this all in one function.
Hopefully if you at the code below I'll make more sense...
the above doesn't work but if I put the last line as:Code:bio_mc.addEventListener(MouseEvent.MOUSE_DOWN, sendToTop); current_mc.addEventListener(MouseEvent.MOUSE_DOWN, sendToTop); news_mc.addEventListener(MouseEvent.MOUSE_DOWN, sendToTop); function sendToTop(e:MouseEvent):void { var maxIndex:Number = layers_mc.numChildren - 1; var texty:String = e.currentTarget.name //trace (e.currentTarget.name) var texty2:String = "layers."+texty+"_content" //trace (texty2) layers_mc.setChildIndex("texty2" as MovieClip, maxIndex); }
it does work. when I trace my texty2 variable it comes out as layers_mc.news_mc_content ...so what's going on, I'm new so I might be missing some obvious syntax mistake or sometime, I don't know! Hope I making sense... Please Help!Code:layers_mc.setChildIndex(layers_mc.news_mc_content as MovieClip, maxIndex);




Reply With Quote