The code is in a child movie clip which is a collectible in a game.. I was trying to make an easy method to remove the child from the screen when the parent called the end game function.. So what I did was make a nowending variable set to false and when it is true the child removes itself automatically
import flash.events.Event;
function randomRange(max:Number, min:Number = -640):Number
{
return Math.random() * (max - min) + min; //equation for random number
}
this.y = randomRange(0) //random y value for the money
this.x = 970; //money starts off the screen so player can prepare for it
this.addEventListener(Event.ENTER_FRAME, moneyfunction);
function moneyfunction (evt:Event):void {
this.x -= 5; //moves the clip from right to left at a rate of 5
if (MovieClip(this.parent).ballcharacter.hitTestObject(this))
{
MovieClip(this.parent).moneycount += 250 * MovieClip(this.parent).moneymultiplier;//add 250 on contact
MovieClip(this.parent).moneycounter.text = "Money: " + MovieClip(this.parent).moneycount.toString();// text field displays money
this.stop();
this.removeEventListener(Event.ENTER_FRAME, moneyfunction); //removes function
this.parent.removeChild(this); //removes the clip from the stage
}
if (this.x <= -475){
this.stop();
this.removeEventListener(Event.ENTER_FRAME, moneyfunction); //removes function
this.parent.removeChild(this); //removes the clip from the stage
}
if (MovieClip(this.parent).nowending == true){
this.stop();
this.removeEventListener(Event.ENTER_FRAME, moneyfunction); //removes function
this.parent.removeChild(this); //removes the clip from the stage
}
}
there's the code.. it works perfectly without this line
}
if (MovieClip(this.parent).nowending == true){
this.stop();
this.removeEventListener(Event.ENTER_FRAME, moneyfunction); //removes function
this.parent.removeChild(this); //removes the clip from the stage
}
but when that's inserted I get an error 1009 everytime the moneyfunction is called.