Skip to main content
Participant
April 26, 2010
Question

removeEventListener function targetting a button on root

  • April 26, 2010
  • 1 reply
  • 840 views

Hi,

I could spend 5 minutes trying to explain to you why I'm targetting root and using frames etc. but it's irrelevant - I HAVE to. In a nutshell, I have to make an .fla that's easily updatable for somebody who knows nothing about AS. I don't know a huge amount myself!

I'm basically making a flick through Flash presentation. Each page/section is on it's own frame on the root timeline. Each page has the same nav, with a button called b_next and b_prev.

On each page an eventListener is added to b_next and b_prev telling it to go to either the next frame of previous frame respectively. The function's that have nextFrame(); and prevFrame(); also have removeEventListeners so that I can add a new eventListener when it gets to the next/prev frame. If I don't do this, then I get "Error #1009: Cannot access a property or method of a null object reference" when I arrive on the next frame.

The problem arises when I have to control b_next and b_prev from within a movieclip on stage. b_next and b_prev are still sitting on the root. Suddenly I get Error #1009 again.

So within the movieclip on stage I have the following code for the buttons:

MovieClip(root).b_next.addEventListener(MouseEvent.CLICK, FR1stFrameNext);

MovieClip(root).b_prev.addEventListener(MouseEvent.CLICK, FR1stFramePrev);

function FR1stFrameNext(event:MouseEvent): void {

    nextFrame();

    trace("shithead")

    MovieClip(root).b_next.removeEventListener(MouseEvent.CLICK, FR1stFrameNext);

    MovieClip(root).b_prev.removeEventListener(MouseEvent.CLICK, FR1stFramePrev);

    mc_fashionrocksvideo.ns.close();

}

function FR1stFramePrev(event:MouseEvent): void {

    TweenMax.to(MovieClip(root).mc_content, .5, {alpha:0, onComplete:MovieClip(root).prev_frame});

    mc_fashionrocksvideo.ns.close();

    MovieClip(root).b_next.removeEventListener(MouseEvent.CLICK, FR1stFrameNext);

    MovieClip(root).b_prev.removeEventListener(MouseEvent.CLICK, FR1stFramePrev);

}

On b_next: nextFrame(); seems to work, trace seems to work and mc_fashionrocksvideo.ns.close(); seems to work. But I don't think the removal of the eventListeners is working as I get Error #1009 - like I used to on my other pages where all of this code was done on the root.

Any ideas?

Thanks,

Gristy

This topic has been closed for replies.

1 reply

Participant
April 26, 2010

Come on America! Wake up! I need you!

P.S. the trace was a swear word, not actually ******** (incase that's not a valid trace)

Darshan_Rane
Inspiring
April 26, 2010

"Each page has the same nav, with a button called b_next and b_prev."

I think you have different btn for each frame with same name, instead have common layer of btns and remove prev btn from first frame and next from last frame.by remove i mean make its visible property false.

Participant
April 26, 2010

Hmmmm, not sure what you're saying...

There are 22 frames. b_next and b_prev are placed on stage on frame 2 in a keyframe and just sit there with the same instance name until the end.

Thank you for your help.