5 Replies Latest reply on Nov 20, 2007 9:08 PM by kglad

    Dynamic buttons from array

    raylaur Level 1
      I'm trying to create a series of buttons from an array. The array contains the names I want on the buttons. I am able to do this by creating empty movie clips with internal textfields using the array index :

      _root.level1Menu = new Array();
      _root.level1Menu = ["File", "Storage", "Security", "Power", "Advanced"];

      for (var i = 0; i<level1Menu.length; i++) {
      _root.createEmptyMovieClip("menu"+i,i);
      _root["menu"+i].createTextField("menuTitle"+i,i,0,0,0,0);
      _root["menu"+i]["menuTitle"+i].text = level1Menu ;

      }

      Once all the button objects are created - how do I assign event handlers to them without having to name them individually?

      I tried assigning the behaviors to them inside of the For loop that created them but it doesn't work. It works outside of the loop when I name them individually. For example I want the text to change color when rolling over.

      _root["menu"+1].onRollOver = function() {
      _root["menu"+1]["menuTitle"+1].textColor = 0x0000FF;

      };