Copy link to clipboard
Copied
My game is a simple drag helicopter_mc to the landing pad and go to next frame. Simple enough but for some reason everytime i reach the pad the #1009 error comes up . please help , I feel like i have to add something to the next frame, but I dont know. Tried researching but I dont even know whats right to look at .
Heres the error :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FinalProjectGame_fla::MainTimeline/handleCollision()
and heres my code
import flash.events.MouseEvent;
import fl.motion.MotionEvent;
stop();
helicopter_mc.addEventListener(MouseEvent.MOUSE_UP, drop);
helicopter_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
helicopter_mc.addEventListener(Event.ENTER_FRAME, handleCollision);
//stage.removeEventListener(Event.ENTER_FRAME,collission)
function drag(event:MouseEvent):void
{
event.target.startDrag();
}
function drop(event:MouseEvent):void
{
event.target.stopDrag();
}
function handleCollision(event:Event):void{
if (helicopter_mc.hitTestObject(cloud1))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud2))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud3))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud4))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud5))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud6))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud7))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud8))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud9))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud10))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud11))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud12))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud13))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud14))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(cloud15))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(missle1))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(missle2))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(heli1))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(heli2))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(heli3))
{
helicopter_mc.nextFrame();
}
if (helicopter_mc.hitTestObject(pad))
{
nextFrame();
}
}
Copy link to clipboard
Copied
My guess would be you have misnamed something.
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).
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now