A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Noobie: How do I remove children?

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    12

    Noobie: How do I remove children?

    I have a particle system that adds however many instances of a movieclip on the stage determined by whatever number I input into my input_txt field. The default value is 5, but you can change it.

    When you change it to 10, the stage adds more and displays 10 instances of the object like it should. The problem however, is that when you set that number back to 5, the number of instances stay at 10, so I'm guessing that this is a child removal problem.

    this is what I have so far:
    Code:
    var numOfParticles = input_txt.text;
    var particles_ary:Array = [];
    
    function updateStage(event:Event):void
    {
    	if (particles_ary.length < numOfParticles)
    	{
    		var ball:ball_mc = new ball_mc();
    		addChild(ball); 
    		ball.x = stage.stageWidth / 2;
    		ball.y = stage.stageHeight / 5;
    		particles_ary.push(ball);
    	}
    	for (var i:uint = 0; i < particles_ary.length; i++)
    	{
    		var particle:ball_mc = particles_ary[i];
    		particles_ary[i].update();
    		if(particle.x > stage.stageWidth + particle.width/2 || particle.x < -particle.width/2 || particle.y > stage.stageHeight + particle.height/2 || particle.y < -particle.height/2)
    		{
    		particle.x = stage.stageWidth / 2;
    		particle.y = stage.stageHeight / 5;
    		}
    		
    	}
    }
    
    input_txt.text = numOfParticles.toString();
    
    function changeNumber(event:Event):void
    {
    	numOfParticles = input_txt.text;
    }
    
    change_btn.addEventListener(MouseEvent.CLICK, changeNumber);
    addEventListener(Event.ENTER_FRAME, updateStage);
    I wrote this fake script to see if this is the general direction I should be taking to solve this problem... Will this work?

    Code:
    if(new input_txt > current input_txt)
    {
    	subtract the two and remove that many children
    }
    else
    {
    	numOfParticles = input_txt.text;
    }
    thx

  2. #2
    Member
    Join Date
    Jan 2009
    Posts
    90
    The command is removeChild, e.g.:

    removeChild(particles[i])

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