Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
The 1009 error indicates that one of the objects being targeted by your code is out of scope. If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved. Then use the trace function to narrow down which object is cooming up null to cause the error.
Copy link to clipboard
Copied
yea this right here is causing the error
if (MovieClip(this.parent).nowending == true){
and this is the code for my parent clip
var nowending:Boolean = false;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now