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:
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: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);
thxCode:if(new input_txt > current input_txt) { subtract the two and remove that many children } else { numOfParticles = input_txt.text; }




Reply With Quote