Skip to main content
Known Participant
April 20, 2010
Answered

Refrencing objects that are not present on frame 1 of a movieclip

  • April 20, 2010
  • 1 reply
  • 326 views

Hi everyone!

I'm working with a movieclip right now that has two frames in it.  I want the user to be able to go back and forth between the pages by clicking on tabs on either page.  The button that they click on is only present on the frame that it is applicable (so, the button to switch to frame 2 is only present on frame 1, and vice versa).

I want to control when they are able to click back and forth, and be able to turn the buttons on and off whenever I need to, but since the button to switch back to frame 1 is only on frame 2, when I reference it from the main timeline, the button registers as a null object.  How do I refrence an object that is not present on the first frame of a clip?

Here's the gist of what I have.  The main timeline has an object called "mAccess" that has 2 frames, Windows and Reports.  At the top there are two tabs, one for Windows, one for Reports.  The Windows tab is only clickable when on the Reports frame (frame 2) and the Reports tab is only clickable when on the Windows frame (frame 1)

Main Timeline:

     mAccess.bReports.addEventListener(MouseEvent.CLICK, gotoreportstab);

     function gotoreportstab(event:MouseEvent) {

          mAccess.gotoAndStop(2);

     }

     mAccess.bWindows.addEventListener(MouseEvent.CLICK, gotowindowstab);           <---  This gives me the error about the null object reference,

     function gotowindowstab(event:MouseEvent) {                                                                 since bWindows does not exist on frame 1 of mAccess.

          mAccess.gotoAndStop(1);

     }               

Thanks for whatever help you can give me!

This topic has been closed for replies.
Correct answer kglad

the bottomline is you can't reference an object that doesn't exist (yet).  the easiest work-around is to make sure your object exists on the frames where you need to reference it.  the object doesn't need to be visible so this isn't much extra-work.  you can add and remove the object from the displaylist as you see fit or enable and disable its visible property. 

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 20, 2010

the bottomline is you can't reference an object that doesn't exist (yet).  the easiest work-around is to make sure your object exists on the frames where you need to reference it.  the object doesn't need to be visible so this isn't much extra-work.  you can add and remove the object from the displaylist as you see fit or enable and disable its visible property. 

kenchtahmAuthor
Known Participant
April 20, 2010

OK, thanks -- it doesn't require much extra work at all, I was just trying to keep my work area clean and as free of extra objects as possible.

Sounds like a job for .visible = false;

kglad
Community Expert
Community Expert
April 20, 2010

that will work.

p.s.  please mark this thread as answered, if you can.