dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [as3] need help with removing all Child

  1. #1
    Senior Member
    Join Date
    Mar 2005
    Posts
    154

    [as3] need help with removing all Child

    Hi there...

    I just need help with my Clip class here...my attempt is attaching some mc's problem the library call "Clip" from mouse click and delete all the attach Clip within 2 seconds after randomly movement...I manage to get attach the Clip and move it as suppose to but have no idea how to eliminate all the Clip from the stage..being struggling here but not to avail..

    my fla..mc in library call "Clip"
    Code:
    stop();
    
    var obj:Clip = new Clip();
    
    stage.addEventListener(MouseEvent.MOUSE_DOWN, startAddClip);
    
    function startAddClip(e:Event):void{
    	obj.addClip(this,this.mouseX,this.mouseY);
    }
    and here are the Clip class file
    Clip.as
    Code:
    package{
    	import flash.display.*;
    	import flash.events.Event;
    	import flash.events.TimerEvent;
    	import flash.utils.Timer;
    	
    	public class Clip extends Sprite{	
    		private var holdSec:Timer;
    		private var clip:Clip;
    		private var total:Number =50;
    		private var mcArr:Array = new Array();
    		private var _stage:DisplayObjectContainer;
    		
    		public function Clip(){
    		}
    		
    		public function addClip(stage_:DisplayObjectContainer,xcoor:Number,ycoor:Number):void{
    			var len:Number;
    			_stage = stage_;		
    			for(var i:Number=0;i<total;i++){
    				clip = new Clip();
    				clip.x = xcoor;
    				clip.y = ycoor;
    				_stage.addChild(clip);
    				mcArr.push(clip);
    			}
    			len = mcArr.length;
    			for(var j:Number=0;j<len;j++){
    				mcArr[j].addEventListener(Event.ENTER_FRAME, goChaos);
    			}
    		}
    		
    		private function goChaos(e:Event):void{
    			e.currentTarget.x += randRange();
    			e.currentTarget.y += randRange();
    			e.currentTarget.alpha = Math.random()*.5+.02;
    			
    			holdSec = new Timer(2000);
    			holdSec.addEventListener(TimerEvent.TIMER, removeClip);
    			holdSec.start();
    		}
    		
    		private function randRange():Number{
        		return Math.random()*10-5;
    		}
    		
    		private function removeClip(e:TimerEvent):void{
    			holdSec.removeEventListener(TimerEvent.TIMER, removeClip);
    			e.currentTarget.stop();
    			//_stage.removeChild(clip);----->HOW TO REMOVE ALL CLIP
    			mcArr.splice(0);
    			trace(mcArr.length);
    		}
    		
    	}
    	
    }
    Any help are really appreciated...at least give me some shed of light or point me my mistake..TQ in advanced

  2. #2
    Senior Member
    Join Date
    Mar 2005
    Posts
    154
    Anyone?super BUMP and here are the source sorry for the broken links...
    Attached Files Attached Files
    Last edited by fifin04; 11-03-2008 at 05:01 AM.

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