Skip to main content
Inspiring
June 11, 2013
Answered

TypeError: Error #1009 but my object is there.

  • June 11, 2013
  • 1 reply
  • 1414 views

Hello all,

On Frame 1 on my main stage I have a Movie clip ( IndexMC )

Inside this movieclip I have a button ( Index_Safety )

On frame 1 I have some AS3:

IndexMC.Index_Safety.addEventListener(MouseEvent.CLICK, INDEX_Safety);

function INDEX_Safety (e:MouseEvent):void

{

                play();

                INDEX_SAFETY=true;

                Sound_Stopper ();

}

When I run, I get this error:

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

                at Newflashlayout_fla::MainTimeline/frame1()[Newflashlayout_fla.MainTimeline::frame1:14]

Normally, when I get this error it Is because it can’t find the object I referenced. However, I am referencing IndexMC.Index_Safety on Frame 1, and the movieclip (IndexMC) with the button(Index_Safety) is on Frame 1.

Newflashlayout_fla.MainTimeline::frame1:14 is:

IndexMC.Index_Safety.addEventListener(MouseEvent.CLICK, INDEX_Safety);

This topic has been closed for replies.
Correct answer sinious

This looks very promising. Thank you very much for this info. I am going to start playing around with this and see how i can improve my projects with it. Thanks again!


You're welcome and if you're all set please mark the thread answered so we can filter unanswered. Good luck!

1 reply

sinious
Legend
June 11, 2013

That line still contains references to objects such as "IndexMC" and inside that "Index_Safety".

Just a note, you should try to keep your object instance names, classes and functions different. It can be really confusing having an instance name of Index_Safety running function INDEX_Safety, even though case sensitivity will allow it.

Run a few traces, see which object it can't find:

trace('1. ' + IndexMC);

trace('2. ' + IndexMC.Index_Safety);

Which returns nothing, 1 or 2? Whichever it is you need to fix the access to that object. Make sure your instance names are what you think they are. 

JordanDJAuthor
Inspiring
June 12, 2013

Thanks for the trace Idea, it showed me that it found IndexMC, however it could not find the button inside of IndexMC. I moved the movieclip about 100 frames in. This brought it just past a small classic tween. The tween moved the movie clip horizontally from slightly off stage right to a position in the uper left of the stage. Once the AS line: IndexMC.Index_Safety.addEventListener(MouseEvent.CLICK, INDEX_Safety); was moved past that tween, i didnt have anymore errors. I checked the MC before and after the tween, and it is the same instance name. Any idea why this happens? it doesnt break my program but i am a neat freak with my code, i like as much as possible to be on frame 1.

sinious
Legend
June 12, 2013

For a classic tween you just want to make sure you assign the code on a keyframe, and use it there. The big problem with classic Tweens is as soon as you create a NEW keyframe, you need to re-apply the same code again. It essentially puts a brand new object on the timeline every keyframe. Hence why modern motion tweens are so much easier to use, they don't have that problem.

Also you really need to make sure your object exists before running code. If your script is in frame 1, it should load everything in frame 1 before running frame code, but it doesn't hurt to make sure. Sometimes objects inside your MovieClips are not marked to be exported in frame 1. Then it wouldn't exist in frame 1 for the script to use. Rare but this can happen. To easily check that just trace on frame 2 and see if it still doesn't exist. If it doesn't it might not be set to export on Frame 1.

If you really want to be a neat freak with the code, get it off the timeline . Put it in an external .as file and set the document class. Control it all from a code file outside the FLA.