1 Reply Latest reply on Jun 9, 2006 7:08 AM by kglad

    Add buttons at runtime and attach events handlers to them

    Level 7

      I need to create several buttons at runtime. I get the buttons data from
      a loaded XML file like this:

      <img> http://www.mysite.com/oneimage.jpg</img>
      <img> http://www.mysite.com/anotherimage.jpg></img>

      With this XML I'll have to create two buttons:

      var btn:Button;
      var btnName:String;
      for ( var i:Number = 0; i < xmlNodes.length; i++ )
      btnName = "node" + i + "_btn";
      _root.attachMovie("node_btn",btnName, _root.getNextHighestDepth());
      btn = eval("_root." + btnName);
      btn._y = 375;
      btn._x = ((btn._width + 5) * i);

      Now I want to add an onRelease event handler for these buttons so when
      each button is pressed the img url will be showed somewhere in the window:

      node0_btn.onRelease = funcion() {

      function loadImg(nodeIndex:Number) {

      How can I do this with actionscript?