jml
jml

Reputation: 1806

Actionscript stops functioning when I navigate away from a certain frame

A friend of mine wants to have some navigation-based mc links in frame 1, then nav to a certain frame, and then have a "back" button. When the nav mc links are clicked, the timeline skips to a given frame label.
Pretty simple.

Most of the links have the same nav mc in them, so when I nav to them, I can also access any of the other frames via something like:

linkg.Contact_btn.addEventListener(MouseEvent.CLICK,Contact_btn_clicked);

function Contact_btn_clicked(e:MouseEvent):void{
    gotoAndStop("ContactPage");
}

The code above is in the first frame, and it is on it's own layer which spans the entirety of the frames in the project, so I would think that these function definitions would persist. But, when I go to a specific link, which does not have the nav mc in it, and then hit that particular frame's "back" button, all of my function definitions are gone, even though the nav mc links are now present, and as I mentioned the listeners should be active.

I am wondering if anyone has experienced this behavior before, or what I could do about it.

Thanks, jml

Upvotes: 0

Views: 90

Answers (1)

weltraumpirat
weltraumpirat

Reputation: 22604

It's not your function declarations that are gone, but the pointer to the button that was set when the declaration is first called.

When you jump to a frame which does not include an instance that was set earlier, that instance is removed from the stage and all listeners now point to an object that is no longer there. If you the add an instance of the same name in another frame, those listeners are not set, even if the listener function is still there and working.

So you will have to call

linkg.Contact_btn.addEventListener(MouseEvent.CLICK,Contact_btn_clicked);

again to make sure the new button also reacts to click events properly.

Another possibility would be to add the same button to every frame of the FLA, but switch to visible = false; when it isn't needed (and back to true when it is, of course).

Upvotes: 1

Related Questions