4 Replies Latest reply on Aug 21, 2006 8:31 PM by Newsgroup_User

    Dynamically creating menu buttons with unique event handlers

    Level 7
      Using F8, AS 2.0

      I'm creating a menu dynamically from XML.

      The script simply attaches a new instance of a Library Item (which is a
      Movie Clip) for each child in a node.

      What I want to do is to create an onMouseUp event handler for each of the
      new buttons dynamically.

      Here's what I've done:

      for (i = 0; i < totalLessons; i++) {

      // attach an instance of the btnReusableLesson to lessonTOC_mc
      lessonTOC_mc.attachMovie("btnReusableLesson", ["lesson" + i], (1000 + i),
      {_x:0, _y:(22 * i)});

      // populate lessonName_txt;
      lessonTOC_mc["lesson" + i].lessonName_txt.text =
      currentCourseLessons .attributes.title;

      // create event handlers for new instance
      lessonTOC_mc["lesson" + i].onMouseUp = function() {
      MAIN_TL.currentLesson = ("lesson" + i);

      This KINDA works, but what happens is that when I click on ANY of the
      buttons, ALL of the button onMouseUp handlers fire, which obviously isn't
      what I want.

      What am I doing wrong and how can I achieve what I want to do?

      Thanks in advance - this place is an invaluable resource.

      Chris Hayes