• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

removeEventListener function targetting a button on root

New Here ,
Apr 26, 2010 Apr 26, 2010

Copy link to clipboard

Copied

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

TOPICS
ActionScript

Views

732

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2010 Apr 26, 2010

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 26, 2010 Apr 26, 2010

Copy link to clipboard

Copied

"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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2010 Apr 26, 2010

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 26, 2010 Apr 26, 2010

Copy link to clipboard

Copied

Got it

U have btns on frame 2 to 22, then instead of removing the listeners why dont u pla y with there visible property. Make them visible - false wher eu try to remove listner and true to where u want the listners.

Not a good solution though, might work..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2010 Apr 26, 2010

Copy link to clipboard

Copied

Hmmmmmm.

Just tried, it didn't work.

Whether they're visible or not they will have an eventListener attached (or not) to them.

Thanks again for your help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2010 Apr 26, 2010

Copy link to clipboard

Copied

LATEST

I think I've worked this out.

It wasn't removing the eventListener that was the problem throwing back the 1009 error.

It was the closure of the NetStream. It couldn't find mc_fashionrocksvideo.ns.close();

But placing the ns on the root seems to have fixed it.

Thanks for your time DarshanRane


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines