Hello I am a new for AS3 and I cannot find the way to remove the child I tried to remove in the class but it doesn’t work, at all.
I made several scenes and when it goes to next scene, want to remove all child displyed currently. Do I need to make removechild in the next scene? but it didn’t work.
The code in the current scene
rfid.addEventListener(PhidgetDataEvent.TAG, onTag1);
rfid.addEventListener(PhidgetDataEvent.TAG_LOST, onTagLoss1);
function onTag1(evt:PhidgetDataEvent):void {
trace(evt);
Tagoutput.text = evt.Data;
if (Tagoutput.text=="01068dc249") {
for (var c = 0; c < 20; c++) {
var white:White = new White();
white.x=900*Math.random();
white.y=900*Math.random();
addChild(white);
trace("alive");
white.name="white"+c;
}
}
}
function onTagLoss1(evt:PhidgetDataEvent):void {
trace(evt);
Tagoutput.text = "";
}
var myTimer2:Timer=new Timer(20000,1);
//Lisenter for Timer
myTimer2.addEventListener(TimerEvent.TIMER, timerListener2);
function timerListener2(e:TimerEvent):void {
mytimeout2=true;
trace("02-elephant");
gotoAndStop(1, "02-elephant");
}
myTimer2.start();
stop();
The code in the class, movieclip(White)
package {
import flash.display.MovieClip;
import flash.events.*;
public class White extends MovieClip {
private var whiteRotation:Number;
public function White() {
//Assign a random rotation speed
this.whiteRotation = Math.random() * 10 - 5;
//Assign a random scale
this.scaleX = 0.5 + Math.random()* 0.2;
this.scaleY = this.scaleX;
//Assign a random alpha
this.alpha = Math.random()*1;
//Add ENTER_FRAME where I do the animation
this.addEventListener(Event.ENTER_FRAME, moveWhite);
}
private function moveWhite(e:Event):void {
this.rotation += this.whiteRotation;
this.x = this.x - Math.random()* 0.8 ;
this.y = this.y - Math.random()* 0.8 ;
if(MovieClip(parent).mytimeout2==true){
//removeEventListener(Event.ENTER_FRAME,moveWhiteDying)
MovieClip(parent).removeChild(this);
}
}
}
}