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

event listener problem

Guest
Jul 20, 2009 Jul 20, 2009

Greetings,

I have the following code in my DocumentClass:

//navBar Listeners
   this.navbar.arch_btn.addEventListener(MouseEvent.CLICK, clickHandler);
   this.navbar.clients_btn.addEventListener(MouseEvent.CLICK, clickHandler);
   this.navbar.news_btn.addEventListener(MouseEvent.CLICK, clickHandler);
   this.navbar.arch_btn.addEventListener(MouseEvent.CLICK, clickHandler);
   this.navbar.land_btn.addEventListener(MouseEvent.CLICK, clickHandler);
   this.navbar.urban_btn.addEventListener(MouseEvent.CLICK, clickHandler);
 
   function clickHandler(event:MouseEvent):void {
    switch (event.currentTarget.name) {
     case "firm_btn":
     this.gotoAndStop(1,"about");
     break;
     case "clients_btn":
     this.gotoAndStop(1,"clients");
     break;
     case "news_btn":
     this.gotoAndStop(1,"newsawards");
     break;
     case "arch_btn":
     reLoad("Transportation");
     this.gotoAndStop(1,"category");
     break
     case "land_btn":
     reLoad("Landscape");
     this.gotoAndStop(1,"category");
     break
     case "urban_btn":
     reLoad("Urban Design");
     this.gotoAndStop(1,"category");
     break;
     default:
     trace (event.currentTarget.name);
    }
   }

However, the navbar movie clip does not enter the stage until frame11 after a brief animation. how can i get these listeners to start listening after frame 11? Thanks

TOPICS
ActionScript
674
Translate
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
LEGEND ,
Jul 20, 2009 Jul 20, 2009

Either move tyhe code to frame 11 or move the navbar to frame 1 and keep it iinvisible until frame 11.

Translate
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
Engaged ,
Jul 20, 2009 Jul 20, 2009

Make the main timeline (with the document class) 1 frame and 1 frame only.

Put the animation into a seperate movieclip and attach a class to it (e.g. Intro).

Attach a class to the navbar movieclip (e.g. NavBar).

Control everything from the document class.

- have the Intro class dispatch an event when animation is done.

- have document class listen to that event (Inro is done) and then display the NavBar

- NavBar will dispatch a custom event when a button is clicked, so that you only need to listen for 1 event for all buttons.

Instead of doing:

this.navbar.arch_btn.addEventListener(MouseEvent.CLICK, clickHandler);
this.navbar.clients_btn.addEventListener(MouseEvent.CLICK, clickHandler);
this.navbar.news_btn.addEventListener(MouseEvent.CLICK, clickHandler);
this.navbar.arch_btn.addEventListener(MouseEvent.CLICK, clickHandler);
this.navbar.land_btn.addEventListener(MouseEvent.CLICK, clickHandler);
this.navbar.urban_btn.addEventListener(MouseEvent.CLICK, clickHandler);

You'd then do:

   this.navbar.addEventListener(NavBarEvent.CHANGE, navChangeHandler);


The NavBarEvent could have a property that indicates which "button" was selected and/or the NavBar class could have a similar property (e.g. selectedLabel) that indicates which navbar item is selected.

This is similar to how a List, ComboBox or DataGrid component works, which have a "selectedIndex" property.

Translate
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
Guest
Jul 20, 2009 Jul 20, 2009

Thanks but I only understand some of that. the problem is that my project is divided into scenes, preloader, home and category view. Frame 11 is actually home frame 1 and Category frame 1 is therefore Frame 12. There is no other way to define the navbar's eventListeners for every keyframe (home fram 1 & category view frame 1) where the navbar is redrawn?

Translate
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
LEGEND ,
Jul 20, 2009 Jul 20, 2009
LATEST

You could also move that code inside the navbar.  That way there wouldn;'t eb any conflict with locating the navbar relative to the code.  You would just have to retarget the cases in the event handler function.

Translate
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