Skip to main content
January 26, 2013
Answered

TypeError: Error #1009: Cannot access a property or method of a null object reference.

  • January 26, 2013
  • 1 reply
  • 1277 views

error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at test1_fla::MainTimeline/openPage1()[test1_fla.MainTimeline::frame2:82]

at test1_fla::MainTimeline/onClickBtn1()[test1_fla.MainTimeline::frame2:52]

code:

line 77 -83:

function openPage1():void

{

          var pageNum11:int;

          pageNum11 = pageNum1 - 1;

          trace("tween" + pageNum11 + pageNum1);

          mainMenu.tweenText.getChildByName("tween" + pageNum11 + pageNum1).addTarget(mainMenu.pane1.text1, 1);

}

line 46-59:

function onClickBtn1(e:MouseEvent):void

{

          switch(e.target)

          {

                    case mainMenu.pane1.btnDown:

                              pageNum1 += 1;

                              openPage1();

                              break;

                    case mainMenu.pane1.btnUp:

                              openPage1();

                              pageNum1 -= 1;

                              break;

          }

}

Can anyone tell me where did I do wrong?

This topic has been closed for replies.
Correct answer kglad

trace( mainMenu.tweenText.getChildByName("tween" + pageNum11 + pageNum1)) the output is null

trace(mainMenu.pane1.text1) the output is[object Text_24]


ok, so mainMenu.tweenText.getChildByName("tween" + pageNum11 + pageNum1) doesn't exist for the variable values that were assigned at the time the trace returned null.  fix that.

1 reply

kglad
Community Expert
Community Expert
January 26, 2013

if line 82 is the addTarget line, then either

  mainMenu.tweenText.getChildByName("tween" + pageNum11 + pageNum1)

or

mainMenu.pane1.text1

don't exist when that code executes.  use the trace function to determine which.

January 26, 2013

both of them exist, I used trace

mainMenu.tweenText.getChildByName("tween" +  pageNum11 + pageNum1) is supposed to be a motion tween

kglad
Community Expert
Community Expert
January 26, 2013

which is line 82?

copy and paste both the trace statements in the context of your code and the trace output.