removeEventListener function targetting a button on root
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 ![]()