1 Reply Latest reply on Jan 30, 2010 5:29 AM by Ned Murphy

    Question regarding action script and creating menus

    jamez24

      I have been using flash for awhile now, and have never formally been trained in web design, so I always question whether I am using best practices. Below is the code that I have written for a menu. Although I try to use script to control everything, I feel there is a more efficient means for doing this. Any help would be appreciated. The site design and work in progress menu can be viewed here: http://www.studiojarch.com

       

      Any tips on how to optimize the code would be appreciated.

       

       

      on (press) {
          if (project._currentframe == 25) {
      }
          else {
              getURL("http://www.studiojarch.com/contact/", "studio_james_cornetet");
              project.gotoAndStop(25);
      }}

       

      on (rollOver) {
          if (_parent.Contact.goalPos == 290) {
              _parent.highlighter.goalPosy = 299;
              _parent.highlighter.goalPosx = 5;
              _parent.highlighter.reverse=false;
              _parent.highlighter.play();
              project.reverse=false;
              project.play();
      }
          else if (_parent.Contact.goalPos == 330) {
              _parent.highlighter.goalPosy = 339;
              _parent.highlighter.goalPosx = 5;
              _parent.highlighter.reverse=false;
              _parent.highlighter.play();
              project.reverse=false;
              project.play();
      }
          else if (project._currentframe == 25) {
              _parent.highlighter.goalPosy = 259;
              _parent.highlighter.goalPosx = 5;
              _parent.highlighter.reverse=false;
              _parent.highlighter.play();
      }
          else {
              _parent.highlighter.goalPosy = 259;
              _parent.highlighter.goalPosx = 5;
              _parent.highlighter.reverse=false;
              _parent.highlighter.play();
              project.reverse=false;
              project.play();
      }}

       

      on (rollOut) {
          if (project._currentframe == 25) {
          project.reverse=false;
      }
          else {
          _parent.highlighter.reverse=true;
          _parent.highlighter.goalPosx = -10;
          project.reverse=true;
          }}

       

      on (release) {
          if (animation_hl_contact._currentframe == 24) {
      }
          else {
      _parent.James_Cornetet.project.gotoAndStop(1);
      _parent.Architecture.project.gotoAndStop(1);
      _parent.Awards.project.gotoAndStop(1);
      _parent.Blog.project.gotoAndStop(1);
      _parent.News.project.gotoAndStop(1);
      _parent.Publications.project.gotoAndStop(1);

       

      _parent.James_Cornetet.reverse=true;
      _parent.Architecture.reverse=true;

       

      _parent.Architecture.goalPos = 100;
      _parent.Awards.goalPos = 130;
      _parent.Blog.goalPos = 160;
      _parent.News.goalPos = 190;
      _parent.Publications.goalPos = 220;
      _parent.Contact.goalPos = 250;

       

          _parent.James_Cornetet.about.gotoAndStop(1);
          _parent.James_Cornetet.cv.gotoAndStop(1);
          _parent.Architecture.category.gotoAndStop(1);
          _parent.Architecture.date.gotoAndStop(1);
          _parent.Archtiecture.bylocation.gotoAndStop(1);
          _parent.Architecture.typology.gotoAndStop(1);
         
          animation_hl_contact.reverse=false;
          animation_hl_contact.play();
          _parent.James_Cornetet.animation_hl_james_cornetet.reverse=true;
          _parent.Architecture.animation_hl_architecture.reverse=true;
          _parent.Awards.animation_hl_awards.reverse=true;
          _parent.Blog.animation_hl_blog.reverse=true;
          _parent.News.animation_hl_news.reverse=true;
          _parent.Publications.animation_hl_publications.reverse=true;

       

      }}

        • 1. Re: Question regarding action script and creating menus
          Ned Murphy Adobe Community Professional & MVP

          One thing that stands out as being undesirable as far as best practices go is that you are placing code on objects (using the on() approach).  The proper approach is to assign instance names to your interactive objects and use them to place all of your code on the timeline where it is readily visible.  In doing so you may just find that alot of the code you show can be modularized into functions that can be shared by different objects rather than having each one carrying a full load on its back. You may find you can pass arguments to shared functions that make the same functions capable of supporting interactions with different objects

           

          Your on(press) call performs an unnecessary conditional test.  If you change the condition to be   if (project._currentframe != 25) you can avoid this.

           

          In your on(rollOver) call's set of conditionals, you have some lines that repeat in each condition, so they can be moved to the end outside the conditionals.

           

          Your on(release) call has the same issue as your on(press) call.  Also the overrun use of the _parent target is an indication that most of the code in this call would likely serve you better sitting in the _parent timeline, and your button could just call that function