I was trying to make snow in flash, when problem appeared. Here's main .fla file AS:
And bell.as:Code:import fl.controls.Slider; import fl.controls.SliderDirection; import fl.controls.CheckBox; import bell; var mc:MovieClip = new MovieClip(); addChild(mc); var windVal:Number = 0; var frq:Number = 1; var dados:Boolean = false; stage.addEventListener(Event.ENTER_FRAME, snow); wind_sldr.addEventListener(Event.CHANGE, wv); herz.addEventListener(Event.CHANGE, ww); cbb.addEventListener(MouseEvent.CLICK, cx); function cx(e:MouseEvent) { dados = cbb.selected; if(!dados) { for(var p:Number = 0; p<mc.numChildren; p++) { //if(Object(mc.getChildAt(p)).devs) { Object(mc.getChildAt(p)).r(); mc.removeChildAt(p); //} } } } function wv(e:Event) { windVal = wind_sldr.value; } function ww(e:Event) { frq = herz.value; } function snow(e:Event) { for(var l:Number = 0; l<frq; l++) { var m:bell = new bell(); mc.addChild(m); } }
when cx() function is run, not every child of mc MovieClip is removed. Why?Code:package { import flash.display.Sprite; import flash.display.MovieClip; import flash.events.Event; import fl.transitions.Tween; import fl.transitions.TweenEvent; import fl.transitions.easing.*; public class bell extends Sprite { public var spd:Number; public var ws:Number; public var wina:Number; public var devs:Boolean; public function bell() { addEventListener(Event.ADDED_TO_STAGE, added); addEventListener(Event.ENTER_FRAME, ef); this.graphics.beginFill(0xFFE9F7); this.graphics.drawCircle(0, 0, Math.random()*5); this.graphics.endFill(); } public function added(e:Event) { this.x = Math.random() * MovieClip(root).stage.stageWidth; spd = 1 + Math.random() * 4; } public function ef(e:Event) { this.y += spd; if (MovieClip(root).windVal!=0) { if (MovieClip(root).windVal != wina) { ws = MovieClip(root).windVal - MovieClip(root).windVal/2 + Math.random()*MovieClip(root).windVal/2; wina = MovieClip(root).windVal; } this.x+=ws; } if (this.y >= MovieClip(root).stage.stageHeight) { removeEventListener(Event.ENTER_FRAME, ef); devs = true; if(!MovieClip(root).dados) { MovieClip(root).mc.removeChild(this); } } } public function r() { removeEventListener(Event.ENTER_FRAME, ef); } } }




Reply With Quote