Skip to main content
January 25, 2013
Answered

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

  • January 25, 2013
  • 1 reply
  • 925 views

error:

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

          at Untitled_fla::MainTimeline/frame1()[Untitled_fla.MainTimeline::frame1:4]

code:

asdf.addEventListener(MouseEvent.CLICK, onClick);

asdfasdf.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void

{

          text1.text = e.target.text

}

asdf is in frame 1

asdfasdf is in frame 2

text1 is in frame 1

how do i get the code to work without causing the error?

This topic has been closed for replies.
Correct answer kglad

if asdfasdf doesn't exist until frame 2, you can't use code referencing it in frame 1.

either move the code or move the object or you'll need to use code to check if frame 2 has played and then execute the code referencing asdfasdf

p.s. an object can exist in frame 1 and not be visible until frame 2 is played

1 reply

kglad
Community Expert
Community Expert
January 25, 2013

one (or more) of the line 4 objects referenced doesn't exist when that code executes.

which is line 4, which frame has that code and are there any referenced objects in more than 1 keyframe?

January 25, 2013

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

          at Untitled_fla::MainTimeline/frame1()[Untitled_fla.MainTimeline::frame1 :2]

the error was actually this one the one in top is another error before

asdfasdf is not in keyframe 1 it's in keyframe 2

is there a way I can make asdfasdf readable for onClick function?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 25, 2013

if asdfasdf doesn't exist until frame 2, you can't use code referencing it in frame 1.

either move the code or move the object or you'll need to use code to check if frame 2 has played and then execute the code referencing asdfasdf

p.s. an object can exist in frame 1 and not be visible until frame 2 is played