3 Replies Latest reply on May 15, 2006 6:23 PM by fourseamer67

    creating function in a loop

      hello --

      my problem is that i am dynamically creating a bunch of buttons in a loop, and want to include a different "onRollOver" function for each button. However, the variables I am setting in the functions are all being overwritten with the value from the last pass through the loop. How can i generate a different body of the function for each button that I'm generating?

      my code:

      var dataindex=0;
      [while loop]
      var bname = "instbut_"+dataindex;
      var button = container.createEmptyMovieClip(bname, 100+dataindex);
      container[bname].onRollOver = function() { trace("my button name is "+bname); }

      when this runs, it correctly generates four buttons -- but when i roll over each, "bname" is always equal to "instbut_3". how can i force it to generate four separate functions, instead of one single one referenced by all the buttons together?

      thanks for any tips!

      -- miranda