A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: removing selected movieclips

  1. #1
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84

    removing selected movieclips

    Hi there!!

    I have a button that clears the stage(removes all mcs) using this code:

    on (press)
    {
    for (name in _root)
    {
    if (typeof (_root[name]) == "movieclip")

    {
    removeMovieClip(_root[name]);
    }
    }

    }

    However I want to keep all the instances of ONE of my movieClips on the stage. anyone has any idea how to do this?

    Cheers!!

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    on (press)
    {
    for (name in _root)
    {
    if (_root[name]._name != "nameToKeep")

    {
    removeMovieClip(_root[name]);
    }
    }

    }

    my syntax migth be a bit off, but I think that is the general idea you are going for.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84
    Thanks kortex for your suggestion, this works so long as you try to keep one instance of a movieClip becuase _name targets one instance of a movieClip at a time( I might be wrong but this is how I think it works). but as I mentioned I want to keep all instances of a particular movieClip on the stage. I am working on it, please let me know if you found a fix for this.

    Thanks

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    Suppose all the movieclips you wanna keep are "keep1", "keep2", "keep3", etc



    on (press)
    {
    for (name in _root)
    {
    if (typeof (_root[name]) == "movieclip" && name.indexOf("keep") == -1)

    {
    removeMovieClip(_root[name]);
    }
    }

    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84
    Thanks Silentweed

    it gave me the right idea, however I modified your code slightly to:

    on (press)
    {
    for (name in _root)
    {

    if (typeof (_root[name]) == "movieclip")
    {
    if(name.indexOf("keep") >= 1)

    {
    //do nothing ignore them all!!
    }
    //else remove everything else!
    else
    {
    removeMovieClip(_root[name]);
    }
    }


    }
    }

    because && condtion cuases problem in removing other mcs when is set to -1
    (until "keep" mc is not set to -1 all mcs remains on the stage)

    thanks anyways it sure helped me!!

  6. #6
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    np dude, however



    if(typeof (_root[name]) == "movieclip" && name.indexOf("keep") == -1 ){}


    is only true when it is a movieclip AND the name does not contain the string "keep" present so the above would get rid of all movieclips which do NOT have the string "keep" in their instance name
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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