Results 1 to 4 of 4

Thread: RemoveChild issue in AS3

  1. #1
    Join Date
    Apr 2009
    Posts
    55

    RemoveChild issue in AS3

    I have an array of MovieClips that i am checking in an enterFrame event and wanted to generate a maximum of 5 childs in a clip called 'placeholder' using a button (placeCloud_1). and whatever the childs will 'float' to the top of the stage. when the y=0 the child must be removed (using the function checkPos() ) so i can add another child without exceding the number of 5 childs. Everything works, exept for the removeChild! i've tried removeChild(this) , this.removeChild(this), parent.this.removeChild(this), parent.this.removeChild(mc), placeholder.removeChild(this) etc... and nothing works.

    When using (this) it throws TypeError: Error #1034: Type Coercion failed: cannot convert global@2f6710d1 to flash.display.DisplayObject. whats this issue can anybody help me

  2. #2
    Join Date
    Dec 2008
    Posts
    183

    Re: RemoveChild issue in AS3

    You need to embed the following code in your program, this will give you the expected result.

    Code:
    event.target.parent.removeChild(event.target);
    and you need to use the best way to clear out a display with this:

    Code:
    while(myMC.numChildren > 0) removeChild(myMC.getChildAt(0));
    Make a container movieclip, attach it, and attach your list items to the container.and If you're looping through a DisplayObject and are basing the loop on numChildren, then no need to remove children as the value of numChildren.

  3. #3
    Join Date
    Apr 2008
    Posts
    193

    Re: RemoveChild issue in AS3

    I found that this is a similar problem to what I was having,The code you have given will help to removes the single instance of the movie clip, but not all instances.Once this has been finalized you would be looping through a DisplayObject and are basing the loop on numChildren, then not all of the children are removed as the value of numChildren changes as you remove the children.

    I have used the following way to remove all the children as follows:

    Code:
    var count:uint = mySprite.numChildren;
    for(var i:uint=0;i<count;i++){
    mySprite.removeChildAt(0);
    }
    Here the Used 0 (zero) index for removeChildAt as everytime you remove an item, it shifts everything in the display list down by 1.

  4. #4
    Join Date
    Dec 2008
    Posts
    183

    Re: RemoveChild issue in AS3

    Thanks for the reply, when i apply your given code in the program at that time it works only for some children's but i was unable to remove children's from the others. Is it possible to delete the holder clip entirely and then recreate it when you press the button to display the list.

Similar Threads

  1. Replies: 6
    Last Post: 12-06-2011, 01:02 AM
  2. MKL issue on MAC OS
    By Channing in forum Operating Systems
    Replies: 5
    Last Post: 25-09-2010, 12:20 PM
  3. DP35DP: memory issue; DVD issue; Lan issue.
    By Rivan in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 29-06-2010, 12:50 AM
  4. Replies: 4
    Last Post: 03-04-2010, 06:03 AM
  5. DNS issue causing "Applying computer setting issue" hang
    By NIcaBoy in forum Small Business Server
    Replies: 2
    Last Post: 14-10-2009, 06:04 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,386,829.22842 seconds with 16 queries