6 Replies Latest reply on Jun 16, 2006 9:03 AM by Peter Lorent

    onRelease to be "listened" for in class for same mc

    Level 7
      Hi,

      I have two classes, both of which take the reference of a movieclip and both
      have to do something when the movieclip is clicked (onRelease). I tried
      using the EventDispatcher, but couldn't get it to work for me.

      Any help will do.

      MyClass1.as
      --------------
      import mx.events.EventDispatcher;
      class MyClass1 {
      var dispatchEvent:Function;
      var addEventListener:Function;
      var removeEventListener:Function;
      var my_mc:MovieClip;
      //
      function MyClass1(mcRef_mc:MovieClip) {
      trace("Init 1");
      my_mc = mcRef_mc;
      EventDispatcher.initialize(this);
      var myObj:Object;
      myObj.onRelease = function(evt) {
      trace("Class 1");
      };
      my_mc.addEventListener("onRelease", myObj);
      }
      }

      MyClass2.as
      --------------
      import mx.events.EventDispatcher;
      class MyClass2 {
      var dispatchEvent:Function;
      var addEventListener:Function;
      var removeEventListener:Function;
      var my_mc:MovieClip;
      //
      function MyClass2(mcRef_mc:MovieClip) {
      trace("Init 2");
      my_mc = mcRef_mc;
      EventDispatcher.initialize(this);
      var myObj:Object;
      myObj.onRelease = function(evt) {
      trace("Class 2");
      };
      my_mc.addEventListener("onRelease", myObj);
      }
      }

      //////////////////////////////////
      On main timeline, I have a dummy movieclip (dummy_mc)

      var c1 = new MyClass1(dummy_mc)
      var c2 = new MyClass2(dummy_mc)