PDA

View Full Version : Error #1009: Cannot access a property or method of a null object reference:presscheck



jakmagi
February 17th, 2010, 10:28 PM
Hullo..
A newbie here..and AS3..
Anyways..I was trying out AS3...when got this kinda error..
-----------------------------------------------------------------------
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at testCollision1_fla::MainTimeline/presscheck()
--------------------------------------------------------------

Anyways,...I created 2 sets of actions in 2 separate keyframes.
I just wanted to try playing in between the different frames..plus a few basic mouse-button interactions.

here's a look at the first actionscript../.
----------------------------------------------------------
stop();
moveblock.addEventListener(MouseEvent.MOUSE_DOWN, startMove);
stage.addEventListener (Event.ENTER_FRAME, presscheck);
toKeyz.addEventListener(MouseEvent.MOUSE_UP, toNextKey);

function presscheck(event:Event):void
{
if(moveblock.hitTestPoint(mouseX, mouseY, true))
{
//trace("they");
checkTxt.text = "Help: " + "them";
}
}


function startMove(evt:MouseEvent):void
{
moveblock.startDrag();
}

function toNextKey(evt:MouseEvent):void
{
gotoAndPlay("keybord");
}

moveblock.addEventListener(MouseEvent.MOUSE_UP, stopMove);

function stopMove(evt:MouseEvent):void
{
moveblock.stopDrag();
checkTxt.text = "Help: block noticed";
if (bgwk.hitTestObject(moveblock))
{
trace("hrthr");
//moveblock.x = bgwk.x;
//moveblock.y = bgwk.y;
//rectangle

}
}
------------------------------------------------

...and here's the second action frame
-------------------------------------------------
stop();

btninviz.addEventListener(MouseEvent.MOUSE_UP, hidemouse);
btnvizy.addEventListener(MouseEvent.MOUSE_UP, showmouse);
//stage.addEventListener(Event.ENTER_FRAME, keepcsr);
toMose..addEventListener(MouseEvent.MOUSE_UP, back21);

function hidemouse(evt:MouseEvent):void
{
Mouse.hide();
}

function showmouse(evt:MouseEvent):void
{
Mouse.show();
}

function keepcsr(evt:Event):void
{
newcsr.x = mouseX;
newcsr.y = mouseY;
}


function back21 (evt:MouseEvent):void
{
gotoAndPlay("mousse");
}

-----------------------------------------------------------

here's me attached fla file..
http://www.mediafire.com/?nmzrxynzkfw
-------------------------------------------------
did skim through a few forums in this Error #1009 problem...am still confused...the only thing I noticed is that the error occurs when i add in the presscheck() and keepcsr() functions....which I suspect that it's related (I might have wrongly called/declared them) in the:

'stage.addEventListener(Event.ENTER_FRAME, keepcsr);', and
'stage.addEventListener(Event.ENTER_FRAME, presscheck);' lines..

Any ideas/suggestions to rectify them?

IQAndreas
February 18th, 2010, 04:29 AM
Error #1009 means that somewhere something is null, and Flash doesn't let you do anything with it, "since face it, it's null! What am I supposed to do?!?" Flash frantically asks.

If you debug by pressing "CTRL+SHIFT+ENTER" you will run the SWF using the debugger, which will give a much more detailed error message and tell you exactly what line your error is at.

My guess is that it's either "moveBlock" or "checkText" that is null. It all depends on what line number you get from debugging as described above. You can check if something is null by doing "trace(moveBlock);". If that traces out null, that is where the problem lies.

dandylion13
February 18th, 2010, 04:47 AM
IQ, you deserve a medal for always answering these! :)

What, we get about 3 or 4 a day, right...? ;)

I hope one of the moderators will post your usual troubleshooting links to a big, blinking sticky with flashing arrows pointing to it on the forum main page.

... moderators, please??

IQAndreas
February 18th, 2010, 05:50 AM
What, we get about 3 or 4 a day, right...? ;)
I have updated my "title text" to reflect this. :azn:

I really should write out a full and better tutorial, but instead I keep copying and pasting the same list again and again and again... Still, it works. :)


Error #1009 is like the common cold of Flash. Everyone get's it, everyone hates it, it appears again and again and again, yet, it is really easy to diagnose and cure...

:wasted: