4 Replies Latest reply on May 5, 2006 7:46 PM by kglad

    setInterval??

    Level 7
      Hi,
      I have some code to dynamically build a menu from an xml file which works
      great, pulls in the button labels, colors etc

      function buildTMenu(xml_doc) {
      currentTWidth = 20;
      trace("building Menu");
      for (var n = 0; n<xml_doc.firstChild.childNodes.length; n++) {
      attachMovie("btn", "btn"+n, n+1);
      attachMovie("menudiv", "menudiv_"+n, n+51);
      this["btn"+n].theText.autoSize = true;
      this["btn"+n].theText.text =
      xml_doc.firstChild.childNodes[n].attributes.btnLabel;
      this["btn"+n].bg._width = this["btn"+n].theText._width+16;
      this["btn"+n].bghl._width = this["btn"+n].theText._width+16;
      this["btn"+n]._y = 0;
      this["btn"+n]._x = currentTWidth;
      this["menudiv_"+n]._x = Math.round(currentTWidth+this["btn"+n].bg._width);
      currentTWidth += this["btn"+n].bg._width;
      // button functions
      this["btn"+n].onRollOver = function() {
      this.bg.colorTransformTo(this.myCTO, 0.2, "easeOutQuad");
      };
      this["btn"+n].onRollOut = function() {
      this.bg.colorTransformTo(100, 0, 100, 0, 100, 0, 0, 0, 0.2,
      "easeInQuad");
      };
      this["btn"+n].onRelease = function() {
      loadMovie("news.swf", dropzone);
      setHLs(this);
      };
      }
      }

      However I want the menu to build over time with a pause as each button
      appears. How do I pause that for loop? I've trie setInterval without much
      success, maybe I'm doing it wrong,

      tia J


        • 1. Re: setInterval??
          kglad Adobe Community Professional & MVP
          try:

          • 2. Re: setInterval??
            jelaplan Level 1
            I suspect that setInterval is asynchronous and kglad's post ensures that the menu works within the interval.
            • 3. Re: setInterval??
              Level 7
              thanks, that worked a treat ;-)


              "kglad" <webforumsuser@macromedia.com> wrote in message
              news:e3d25e$4u2$1@forums.macromedia.com...
              > try:
              >
              >
              >
              > function startBuildTMenu(xml_doc) {
              > currentTWidth = 20;
              > trace("building Menu");
              > n = 0;
              > buildMenuI = setInterval(buildMenuF, 200, xml_doc);
              > }
              > function buildMenuF(xml_doc) {
              > attachMovie("btn", "btn"+n, n+1);
              > attachMovie("menudiv", "menudiv_"+n, n+51);
              > this["btn"+n].theText.autoSize = true;
              > this["btn"+n].theText.text =
              > xml_doc.firstChild.childNodes[n].attributes.btnLabel;
              > this["btn"+n].bg._width = this["btn"+n].theText._width+16;
              > this["btn"+n].bghl._width = this["btn"+n].theText._width+16;
              > this["btn"+n]._y = 0;
              > this["btn"+n]._x = currentTWidth;
              > this["menudiv_"+n]._x =
              Math.round(currentTWidth+this["btn"+n].bg._width);
              > currentTWidth += this["btn"+n].bg._width;
              > // button functions
              > this["btn"+n].onRollOver = function() {
              > this.bg.colorTransformTo(this.myCTO, 0.2, "easeOutQuad");
              > };
              > this["btn"+n].onRollOut = function() {
              > this.bg.colorTransformTo(100, 0, 100, 0, 100, 0, 0, 0, 0.2,
              "easeInQuad");
              > };
              > this["btn"+n].onRelease = function() {
              > loadMovie("news.swf", dropzone);
              > setHLs(this);
              > };
              > n++;
              > if (n>=xml_doc.firstChild.childNodes.length) {
              > clearInterval(buildMenuF);
              > }
              > }
              >


              • 4. Re: setInterval??
                kglad Adobe Community Professional & MVP
                you're welcome.