1 Reply Latest reply on May 31, 2008 6:10 AM by AunStudio

    onPress doesn't work on image...

    AunStudio
      Hi there,

      I am having a problem when trying to add an onPress handler to a JPG which is loaded into a movieclip.
      onPress doesn't work.

      ActionScript Code:

      for (i=0; i<ecards.length; i++) {
      var mc:MovieClip = attachMovie("recipient", "recipient"+i, i);
      mc.loadMovie("images/button.jpg");
      mc.onPress = function(){
      trace(this._name);
      }

      }

      "recipient" is a 100x75 rectangle (same size as JPG).
      if I comment the line "mc.loadMovie("images/button.jpg");" it displays only the original mc and traces the name property, but when I load the image into it, it doesn't trace it anymore.

      Any help would be appreciated.
      Thanks in advance!
        • 1. Re: onPress doesn't work on image...
          AunStudio Level 1
          I got a solution from Ali Inhan at Actionscript.org:

          for (i = 0; i < ecards.length; i++) {
          var mcl:MovieClipLoader = new MovieClipLoader();
          var listener:Object = new Object();
          mcl.addListener(listener);
          listener.onLoadInit = function(m:MovieClip) {
          m.onPress = function() {
          trace(this._name);
          }
          }
          var mc:MovieClip = attachMovie("recipient", "recipient" + i, i); mcl.loadClip("images/button.jpg", mc);
          }