Skip navigation
scasey1982
Currently Being Moderated

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

Jul 21, 2009 10:58 AM

I am having a problem with this error when I am trying to use a function for a button.  Everything works fine when I have it on frame 1, but when I add a preloader to frame 1 and put my content on frame two I recieve the #1009 error.

 

When I tested my code with just a simple function I still got the error.  the code is below, Any help would be greatly appreciated!

****Code for Preloader(Frame1)*******

stop();

loaderInfo.addEventListener(ProgressEvent.PROGRESS, updatePreloader);

 

 

function updatePreloader(evtObj:ProgressEvent):void
{
    var percent:Number = Math.floor((evtObj.bytesLoaded*100)/evtObj.bytesTotal);
    preloader_txt.text=percent+"%";
    if (percent>=100){
        nextFrame();
    }
       
}

 

 

****Code for Main Content (Frame 2)****

 

stop();
//Import the necessary files for all of the tweening
//--------------------------------------------------------
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;

 

//---------------------------------

 

//Move all of the text off screen and set them invisible
//--------------------------------------------------------
featuresText_mc.alpha=0;
featuresText_mc.y=-500;
viewCottageText_mc.y=-500;
rateInfo_mc.alpha=0;
rateInfo_mc.y=-500;
viewCottageText_mc.alpha=0;

contactInfoText_mc.alpha=0;
//--------------------------------------------------------
viewCottage_btn.addEventListener(MouseEvent.CLICK, goCottage); function goCottage(evtObj:MouseEvent){
    trace("test")
}

 

***Any Help would be greatly Appreciated***

 
Replies
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 21, 2009 11:01 AM   in reply to scasey1982

    click file/publish settings/flash and tick "permit debugging" and retest to pinpoint your error.  the frame and line number that's causing the error will be displayed.

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 21, 2009 12:00 PM   in reply to scasey1982

    a function won't give a null object reference error.   the line above your function could be causing the error but it should be obvious which line is causing the error because the lines are numbered.  which line is referenced in the error message and copy and paste the exact error message.

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 21, 2009 12:37 PM   in reply to scasey1982

    if

     


    viewCottage_btn.addEventListener(MouseEvent.CLICK, goCottage);

     

    is the line referenced in the error message, viewCottage_btn doesn't exist when that error message occurs.

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 21, 2009 12:52 PM   in reply to scasey1982

    that depends how you create that instance.

     

    if it's done on the timeline, then you should have that code attached to the first frame where that object first appears and never remove that object for as long as it's needed.

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 21, 2009 2:18 PM   in reply to scasey1982

    use a trace() statement to confirm that the error occurs as the playhead enters the frame that contains your button for the first time.   if so, you have a typo either in the code or the properties panel.  use copy and paste to make sure they match.

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 21, 2009 5:09 PM   in reply to scasey1982

    is the code that causes the error message and the button in the same frame?  if so, you have a typo.

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 22, 2009 9:16 AM   in reply to scasey1982

    you're welcome.

     
    |
    Mark as:
  • Currently Being Moderated
    May 11, 2011 11:08 AM   in reply to kglad

    Hi kglad,

     

    I recently suffered a similar problem and reading your advice here helped me get it working again. Just wanted to let you know your helping us all and we appriciate it

     

    THANK YOU!!!

     

    p.s. you're a genious

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points