Copy link to clipboard
Copied
Hi,
I am working in Flash Professional CC, testing an old game with two levels and a win and lose screen. The game works until you get to the second level scene. Once you're there, the 1006 output errors appear.
TypeError: Error #1006: removeChild is not a function.
at final_project_2_fla::golem_22/onHealth()[final_project_2_fla.golem_22::frame1:6]
removeChild( ) is only used in the golem health function which it is referencing., so I know the problem's probably there. Thing is, I don't know why Flash is telling me I'm using removeChild as a function or why a sixth frame is being reference. Unless that's a code line references?
Here's the code from the enemy I was talking about.
var health:int=4;
this.addEventListener(Event.ENTER_FRAME,onHealth);
function onHealth(evt:Event):void{
if(health==0){
this.removeEventListener(Event.ENTER_FRAME,onHealth);
Object(parent).removeChild(this);
}
}
Also, when you beat the game you get this error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at final_project_2_fla::MainTimeline/onLoop2()[final_project_2_fla.MainTimeline::frame4:27]
I read up on the 1006 error because it's really common. I know the steps begin with tracing something, but I'm not sure what to begin tracing because it's referencing the function, but I think it's refencing the 27th line of a fourth frame? Which doesn't make sense because I don't have a fourth frame there.
Here's the onLoop2 function, if it will help out
function onLoop2(evt:Event):void {
charMove();
if(char.hitTestObject(bgr.page1)){
bgr.page1.visible=false;
uipage1.visible=true;
removeListeners2();
echannel=ff.play(0,1);
gotoAndStop(1, "win");
}
///collision with golem 1
if(char.hitTestObject(bgr.golem)){
trace(attack);
if(attack){
bgr.golem.x+=50;
bgr.golem.health--;
attack=false;
}else{
if(bgr.golem.arms.currentFrameLabel=="idle"){
bgr.golem.arms.gotoAndPlay("attack");
}
health-=5;
bgr.x+=10;
}
}
if(health<75){
hp4.visible=false;
}
if(health<50){
hp3.visible=false;
}
if(health<25){
hp2.visible=false;
}
if(health<1){
hp1.visible=false;
removeListeners2();
gotoAndStop(1, "lose");
}
Thank you for your time and effort.
Copy link to clipboard
Copied
When you read errors, the references to find the code are frame:line as you thought it might be. The 1006 error is occuring at frame 1 line 6. The 1009 error is occuring at frame 4 line 27.
For the 1006 error, what you could do is trace the the parent object to see what it is. The problem might be as simple as you trying to cast it as an Object, when you might need to be casting it as a DisplayObjectContainer or some other type that has the removeChild function in its arsenal.
The 1009 error indicates that one of the objects being targeted by your code is out of scope. This could mean that the object....
- is declared but not instantiated
- doesn't have an instance name (or the instance name is mispelled)
- does not exist in the frame where that code is trying to talk to it
- is animated into place but is not assigned instance names in every keyframe for it
- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).