A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Managing Layers & using variables... help!

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    117

    Managing Layers & using variables... help!

    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...


    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);
       
       
    }
    the above doesn't work but if I put the last line as:


    Code:
      layers_mc.setChildIndex(layers_mc.news_mc_content 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!

  2. #2
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    layers_mc.swapChildren(layers_mc.getChildAtIndex(0 ), chosenMC);

    try using that method
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center