• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Expert ,
Jul 17, 2009 Jul 17, 2009

Copy link to clipboard

Copied

Hi,

I've used a button from Components Panel, added instance name of home_btn and added AS code like that:

home_btn.addEventListener(MouseEvent.CLICK, goHome);

function goHome(Event:MouseEvent):void
{
    gotoAndStop(1);
}

SO theoratically it should jump back to frame 1 but I'm getting this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at index_fla::MainTimeline/frame1()

Adobe Community Expert
Adobe Certified Professional
TOPICS
ActionScript

Views

4.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 17, 2009 Jul 17, 2009

Copy link to clipboard

Copied

Are you certain that you assigned the instance name you indicate (assigned it in the properties panel)?

If so, does that button exist when/where that code executes?  If it is somewhere down the timeline, or a timeline, the code will not see it.

If so, does the button have a timeline tween of any sort applied to it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2009 Jul 19, 2009

Copy link to clipboard

Copied

The button appeared on the stage on frame 10 whereas the code was placed on frame1.

I moved the button to the first frame and now it works.

If i don't want to see the button on the first frame, what would I do? If I move the piece of code assigned for the Home button to frame 10 on actions layer, I won't see the code for other buttons unless I copy this code again...

Adobe Community Expert
Adobe Certified Professional

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 19, 2009 Jul 19, 2009

Copy link to clipboard

Copied

You can set the button's visible property to false when you don't want to see it and true when you do want to see it.

I am not sure what the issue is with moving the code to frame 10 where the button is.  How would the other buttons be using that same code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 19, 2009 Jul 19, 2009

Copy link to clipboard

Copied

I am having the same issue. I have put my eventListeners for my navbar into the DocumentClass, but the navbar does not appear until frame 11. How can i make the event listerners kick in on frame 11?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 19, 2009 Jul 19, 2009

Copy link to clipboard

Copied

Hi,

If I remember correctly that error refers to an object or function hat doesn't exist. You'll need to check the instance name of the button and the name of the frame to make sure they correspond with what's written in the code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 21, 2009 Jul 21, 2009

Copy link to clipboard

Copied

could you use addFrameScript to add the eventlisteners to the frame when it loads then just declare your functions in the navigation class like you are doing?

That way the script will still be in the document class, but won't execute till you reach that frame.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 21, 2009 Jul 21, 2009

Copy link to clipboard

Copied

You mean add the listener event to the frame?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 22, 2009 Jul 22, 2009

Copy link to clipboard

Copied

Right, so somewhere in your document class you have a function that you want called when you reach a button on Frame 10 in your main timeline. So you put in the document class constructor.....

addFrameScript(9, theFrameCode); //remember under the hood frames are zero based!

Then also in the document class you create a function called

function theFrameCode()

{

     //inside here you add the eventlistener for the button that is on this frame

     Frame10_btn.addEventListener(MouseEvent.CLICK, theDocClassFunctionToCall);

}

I think that will work won't it? So the script will be added to frame 10 where my button exists and then it can call back to the document class function for processing. The code is all in your document class and you don't need a reference to the button that only exists on frame 10 because you are not attempting to access it until it is in scope.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2009 Aug 04, 2009

Copy link to clipboard

Copied

LATEST

It makes sense that it doesn't work because the button is not on frame 1 where I have AS code.

I will make the button invisible on frame 1.

Thanks for all the help.

Adobe Community Expert
Adobe Certified Professional

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 17, 2009 Jul 17, 2009

Copy link to clipboard

Copied

I guess your problem is here:

home_btn.addEventListener(MouseEvent.CLICK, goHome);

function goHome(Event:MouseEvent):void
{
    gotoAndStop(1);
}

Change it to

home_btn.addEventListener(MouseEvent.CLICK, goHome);

function goHome(evnt:MouseEvent):void
{
    gotoAndStop(1);
}

Event is the class name and you can not use a class name as a argument name. also AS3.0 is case sensitive so event/evnt as an argument name will still work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 17, 2009 Jul 17, 2009

Copy link to clipboard

Copied

Good catch!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2009 Jul 19, 2009

Copy link to clipboard

Copied

No, this doesn't help.

Adobe Community Expert
Adobe Certified Professional

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 19, 2009 Jul 19, 2009

Copy link to clipboard

Copied

there's no problem using Event as an argument and there's no problem with the code you posted.  the problem is probably in frame 1 where something referenced no longer exists.

to confirm, click file/publish settings/flash and tick "permit debugging".  retest and check the line number causing the error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 21, 2009 Jul 21, 2009

Copy link to clipboard

Copied

could you use addFrameScript to add the eventlisteners to the frame when it loads then just declare your functions in the navigation class like you are doing?

That way the script will still be in the document class, but won't execute till you reach that frame.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines