A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Make a movie clip always be on top

  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    60

    Make a movie clip always be on top

    I have a bunch of movieclips which constantly do the following:

    mc.parent.addChild(mc);

    as in bring themselves on top. I want a movie clip to always stay blocking them, without adding it to the stage every frame, which is unnecessary memory usage.
    That's it, I'm fed up with having my barely-legal signatures criticized.

  2. #2

  3. #3
    Senior Member
    Join Date
    May 2009
    Posts
    138
    It seems this is one of the things that became more annoying in the switch to AS3 from AS2. I think in AS2 you could just define a really large depth for the one you wanted to keep in front, but in AS3 depth is one-for-one with child objects. Anyway, what you probably want to do is use swapChildren() and every time you add an object, swap its position with the one you want to keep on top. Obviously if you are adding multiple objects in one go you'll only need to do this once with the last one each time.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The displayList is actually a tree, so what you can do is add another layer in the tree by putting in separate containers.

    Code:
    var normalContainer:Sprite = new Sprite();
    var alwaysTopContainer:Sprite = new Sprite();
    
    addChild(normalContainer);
    addChild(alwaysTopContainer); 
    
    //always add other children to normalContainer, and stuff in alwaysTopContainer will remain on top of them.

  5. #5
    Senior Member
    Join Date
    May 2009
    Posts
    138
    Touché. I think I'm gonna like it here.

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