4 Replies Latest reply on Apr 10, 2007 12:13 PM by Peter Pawinski

    Problems attaching event handler to MovieClip

    Peter Pawinski
      I have a bit of thumbnail generation code that looks like this:

      for (var i = 1; i <= 5; i++) {
      filename = "Images/Thumbnails/thumb" + i + ".jpg";
      curr_thumb = thumbstrip_mc.thumbnails_mc.attachMovie("thumbnail", "thumb" + i);
      curr_thumb.loadMovie(filename);
      curr_thumb.onRelease = sayHello;
      curr_thumb._x = ((i - 1) * 125) + 10;
      curr_thumb._y = 25;

      }

      Basically, the structure of my code is as follows:

      _level0.thumbstrip_mc = elements of a thumbnail strip. This includes a background movie clip, a bar with an arrow pointing either up or down depending on whether the strip is open or closed, and a collection of thumbnail images.

      _level0.thumbstrip_mc.thumbnails_mc = a container for all the thumbnails

      _level0.thumbstrip_mc.thumbnails_mc.thumb1 (thumb2, thumb3 ... thumb 5) = the thumbnail images themselves.

      I want to attach an onRelease event handler onto thumb1, thumb2, thumb3, etc... At the moment, the event handler directs to a simple trace function called sayHello(). However, it doesn't work. My mouse does not change from an arrow to a hand, indicating thumb1.onRelease is not handling any events. I even commented out all other event handlers on that level to make sure it wasn't getting intercepted by another event handler on a parent timeline, but that wasn't the problem.

      I'm guessing, then, that my problem must have something to do with the loadMovie method. It's wiping out my handler, right? I'm guessing the handler is attaching before the movie clip is dynamically loaded in? What's the easiest way to fix this? Or is it another problem?