Instances disappearing
Well this is the thing, I have an array of Moviecclips, and I want a random movieclip from that array to appear on stage every certain amount of time.
I made a class that adds a child to the variable, the problem is that sometimes the instances disappear.
here's the code of the class:
import MC1 //the movieclips
import MC2
import MC3
public class theclass extends MovieClip
{
var arrayA:Array = new Array(MC1,MC2,MC3);
var containerM:MovieClip;
var Speed:int = 7
public function theclass()
{
containerM = arrayA[int(Math.random()*3)];
this.addChild(containerM);
addEventListener(Event.ENTERR_FRAME, eFrame);
}
private function eFrame(event:Event):void
{
this.x -= Speed;
if(this.x < 0 - this.width)
{
removeEventListener(Event.ENTER_FRAME,eFrame);
if(this.parent)
{
this.parent.removeChild(this);
}
}
Now I call it from stage:
var min:int = 0;
var limit:int = 40;
function repeat(event:Event):void
{
min++
if(min>= limit)
{
var MoC:theclass = new theclass();
Moc.x = stage.stageWidth;
Moc.y = stage.stageHeight/2;
addChild(Moc);
min = 0;
}
}
stage.addEventListener(Event.ENTER_FRAME,repeat);
So here's basically the code, so can anyone tell me why the instance disappears before getting to the other side of the stage? or what's the problem?
