A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Removing previous movie clip when new page is opened

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    23

    Removing previous movie clip when new page is opened

    I am rebuilding my website and need help in how to remove a mc when another mc is clicked.


    http://www.khawkinsdesign.com/atest/index.html


    The movie clips are pages and if you check the link you will see the pages aren't removed they simply stay on the page when the new mc appears.


    This is the relevant part of the .as which appears to have a remove code but doesn't seem to take affect.


    ------
    function navigate (e:MouseEvent):void {
    trace (e.target.name);

    // Remove the current movie clip
    container_mc.removeChildAt (0);

    switch (e.target.name) {
    case "one_mc":
    var newOne:One = new One ();
    container_mc.addChild (newOne);
    break;

    case "two_mc":
    var newTwo:Two = new Two ();
    container_mc.addChild (newTwo);
    break;

    case "three_mc":
    var newThree:Three = new Three ();
    container_mc.addChild (newThree);
    break;


    ---

    If you can tell me what should be added it would be really appreciated.

    Many Thanks,

    KJoe

  2. #2
    Junior Member
    Join Date
    Feb 2008
    Posts
    12
    the problem you have is you have more then 1 displayobject in the container_mc. you have 3 options:
    1. always addChildAt(page,0) for every page
    2. make an array of pages and remove any/all pages from the stage on every navigation click
    3. make it so only the pages are in the container_mc

  3. #3
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Your nearly there, instead of
    Code:
    // Remove the current movie clip
    container_mc.removeChildAt (0);
    Do this

    Code:
    while(container_mc.numChildren > 0) container_mc.removeChildAt (0);
    This will remove everything from the container before anything get added.
    Last edited by ilike2; 04-03-2011 at 04:24 AM. Reason: typo

  4. #4
    Junior Member
    Join Date
    Feb 2008
    Posts
    12
    good idea but he has 5 other non-page objects in the container according to firebug, he would have to remove them before using that code.

  5. #5
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Quote Originally Posted by solomondg1 View Post
    good idea but he has 5 other non-page objects in the container according to firebug, he would have to remove them before using that code.
    I assume the container movie clip only holds the pages and not the other non-page objects.

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