A Flash Developer Resource Site

Results 1 to 12 of 12

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

  1. #1
    Member
    Join Date
    Dec 2005
    Posts
    90

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

    Hi,

    I am referencing a button that is within another MC on my main stage. The code I have on the first frame of my movie in the actions time-line is the following:

    Actionscript Code:
    this.slideout_MC.info_btn.addEventListener(MouseEvent.MOUSE_DOWN, myHandler);
    function myHandler(event:MouseEvent):void {
        navigateToURL(new URLRequest("http://www.mywebsite.com/page2.html"), "_self");
    }

    And the error i keep receiving in the error panel is:

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


    Can anyone please help me understand why it's saying this and to figure out how to make my button work?

    Thanks in advance of any suggestions/advice,

    Cheska


    PS) Eventually i will have 6 buttons referenced in the same way. this seems like an awful lot of code compared to the old way of getting buttons to work in MX, albeit i understand code in the time-line is better than on the stage.. but still seems like a lots of code per button.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Do a trace:
    trace(slideout_MC.info_btn);
    and see what you get.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    Dec 2005
    Posts
    90
    Hi Cancerinform and thanks for trying to help me out.

    If I place the trace directly after the button event code on frame one, nothing happens. No trace output and no compiler errors.

    If I place the trace after the stop(); command on frame 20 within the actual slideout_MC (the last frame), I still get no trace but I get a compiler error:

    1120: Access of undefined property slideout_MC.

    ??

    Cheska

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    If you don't get any trace output, the error has occurred before. So place the trace above the button event code or further above until you get a trace.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Member
    Join Date
    Dec 2005
    Posts
    90
    If I place the button directly on the stage on the first frame of the movie, and reference that one in my button code instead (rather than the instance within the slideout_MC ), and use the following code on the first frame:

    Actionscript Code:
    info_btn.addEventListener(MouseEvent.MOUSE_DOWN, myHandler);
    function myHandler(event:MouseEvent):void {
        navigateToURL(new URLRequest("http://www.mywebsite.com/page2.html"), "_self");
    }

    Then it works!

    So my original code just can't find my button when it's inside slideout_MC ...

    But I do need it to be in slideout_MC

    What can I do to fix this?

    PS) I use the target helper in my actions pane to locate the info_btn in my slideout_MC , so the path is correct.

  6. #6
    Member
    Join Date
    Dec 2005
    Posts
    90
    Hi Cancerinform,

    I can't get a trace output no matter where i put the trace.

    There are only two pieces of code in my whole movie.

    The button code on very first frame of the main stage.

    and the stop(); code on the last frame of the slideout_MC.

    the slideout_MC is the only MC on the stage.

    I can't seem to get a trace output using that trace code no matter where i put it...?

  7. #7
    Member
    Join Date
    Dec 2005
    Posts
    90
    what does the compiler error mean when it says

    '1120: Access of undefined property slideout_MC.'

    what's the undefined property??

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Quote Originally Posted by Cheska View Post
    what does the compiler error mean when it says

    '1120: Access of undefined property slideout_MC.'

    what's the undefined property??
    It means there is no identifier called slideout_MC. If at one point you have a line like this:
    var slideout_MC:MovieClip;
    then slideout_MC would be null. Have you given slideout_MC a name in the property inspector?
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    Member
    Join Date
    Dec 2005
    Posts
    90
    Hi again :-)

    Yes, I named it slideout_MC in the property inspector.

    Usually when i forget to give an MC an actual name in the property inspector, when using the target helper, the actions pane puts the MC in parenthesis and gives a warning that you have to name the MC to target it correctly...

    but this is not the case, it is definitely named...

    ?

  10. #10
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    However, in frame 20 the object does not exist. Did you do trace in frame 1 of only slideout_MC? Sorry if it sounds stupid, but do you really have info_but in that MovieClip and named? You can also try
    trace(slideout_MC.getChildByName("info_but"));
    - The right of the People to create Flash movies shall not be infringed. -

  11. #11
    Member
    Join Date
    Dec 2005
    Posts
    90
    There's no way you sound stupid. I'm sure I'm the stupid one here...

    However, yes it is definitely named info_btn.

    Though info_btn doesn't actually exist in the movie until about frame 10 of slideout_MC.

    I've managed to get it to work by putting the button event code on line 20 of the slideout_MC.

    But I thought the whole idea was to have all code (other than stop(); commands) on the first frame of the movie. I thought that was the entire concept of AS3. So that's why I was trying to put the code on frame 1 of my main time-line. I don't understand why the target path wasn't working.

    I understand why flash is evolving, all for the better and all that... I can't say i'm thrilled about it taking me near a week to accomplish what used to take 2 seconds in MX!!

    I now have something akin to this on frame 20 of my slideout_MC, which seems like a crazy amount of code to get 4 buttons to click to 4 URLS:

    Actionscript Code:
    info_btn.addEventListener(MouseEvent.MOUSE_DOWN, myHandler);
    function myHandler(event:MouseEvent):void {
        navigateToURL(new URLRequest("information.html"), "_self");
    }

    specialized_btn.addEventListener(MouseEvent.MOUSE_DOWN, myHandler2);
    function myHandler2(event:MouseEvent):void {
        navigateToURL(new URLRequest("specialized.html"), "_self");
    }

    collaborative_btn.addEventListener(MouseEvent.MOUSE_DOWN, myHandler3);
    function myHandler3(event:MouseEvent):void {
        navigateToURL(new URLRequest("collaborative.html"), "_self");
    }

    test_btn.addEventListener(MouseEvent.MOUSE_DOWN, myHandler4);
    function myHandler4(event:MouseEvent):void {
        navigateToURL(new URLRequest("testimonials.html"), "_self");
    }


    Thank so much for your help cancerinform. I really appreciate it. I wouldn't have figured it out this far without you.

  12. #12
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Quote Originally Posted by Cheska View Post
    Though info_btn doesn't actually exist in the movie until about frame 10 of slideout_MC.
    That is the problem of using frames. In frame one the compiler does not know that in frame 10 there is a button. And in frame 20 there is no movieclip so the compiler gives you an error.

    If you don't want certain objects to be shown until a certain frame, make them invisible.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center