2 Replies Latest reply on Apr 22, 2006 11:56 AM by aniebel

    function dilemma

    aniebel Level 2
      Hello, I'm trying to clean up my code and thought I would try to write a function for repetetive AS I have at each section of my main timeline. The only difference was the mc name and xml node. So I tried to take the AS from each frame and place it in a function on the first frame of the movie and call that function at each section but I've done something wrong because it's not running it upon entering each section. Any suggestions?

      Original AS from each section:
      this.stop();
      this.newsNav_mc.onEnterFrame = function() {
      if (this._currentframe == 24 || this._currentframe == 64) {
      sContent = xnNews.attributes.sectionText;
      }
      delete this.onEnterFrame;
      };
      On first frame of main timeline:
      //function for each section when entered
      function enterSection(mcName:String, xmlName:XMLNode) {
      this.mcName.onEnterFrame = function() {
      if (this._currentframe == 24 || this._currentframe == 64) {
      sContent = xmlName.attributes.sectionText;
      delete this.onEnterFrame;
      trace ("function ran");
      }
      };
      };
      At each section (frame label) on main timeline:
      this.stop();
      this.newsNav_mc.gotoAndPlay("openR");
      enterSection("newsNav_mc", "xnNews");
        • 1. Re: function dilemma
          TimSymons Level 1
          It seems that you should just pass the movieClip and not just the name of the clip as a string. Try the following changes:

          Define your function like this:

          function enterSection(mcName:MovieClip, xmlName:XMLNode):Void {
          mcName.onEnterFrame = function() {
          if (this._currentframe == 24 || this._currentframe == 64) {
          sContent = xmlName.attributes.sectionText;
          delete this.onEnterFrame;
          trace ("function ran");
          }
          };
          }

          Then change your calls to look like this:

          this.stop();
          this.newsNav_mc.gotoAndPlay("openR");
          _root.enterSection(this.newsNav_mc, xnNews);



          Tim
          • 2. Re: function dilemma
            aniebel Level 2
            Thanks Tim, I can see how it wouldn't work now. Fantastic!