3 Replies Latest reply on Jul 6, 2006 10:32 AM by Newsgroup_User

    Class Question

    Tolk Level 1
      I'm trying to make a group of movieClip instances (linked to the below class) lock to a grid when the user drags and realeses them. The grid locking code works fine but the code only works for one instance and it will start and stop drag where ever you click on the screen, not jsut over the instance.
      I'm fairly new to writing classes so i'm not sure how i'd go about correcting this, thanks for any help.

      class com.objects.OSIcons extends MovieClip {
      public function OSIcons() {
      }
      public function stopDragGrid() {
      stopDrag();
      this._x =(Math.round(this._x / (this._width+10)))*(this._width+10);
      this._y =(Math.round(this._y / (this._height+10)))*(this._height+10);
      }
      public function onMouseDown() {
      startDrag(this);
      }
      public function onMouseUp() {
      stopDragGrid();
      }
      }
        • 1. Re: Class Question
          Tolk Level 1
          ok i changed the code to this:

          class com.objects.OSIcons extends MovieClip {
          public function OSIcons() {
          this.onMouseDown =this.MU;
          //this.onMouseUp =this.MU;
          this.onRollOver = this.MD;
          }
          private function MD() {
          this.startDrag();
          }
          private function MU() {
          this.stopDrag();
          this._x =(Math.round(this._x / (this._width+10)))*(this._width+10);
          this._y =(Math.round(this._y / (this._height+10)))*(this._height+10);
          }
          }

          and now it works, but it's using the onRollOver Event rather than onMouseDown which is what i want. There's something up with onMouseDown, when you use it outside a class it on fires when mouse is over the movieClip and mouse is down. When i use it inside the class it fires wherever the mouse is. Is there a work around for this?
          • 2. Re: Class Question
            Tolk Level 1
            Ok lol, seem to be talking to myself but here's the solution i found if anyone is interested:

            class com.objects.OSIcons extends MovieClip {
            public function OSIcons() {
            this.onMouseDown =this.MD;
            this.onMouseUp =this.MU;
            }
            private function MD() {
            var temp:Boolean = this.hitTest(_root._xmouse, _root._ymouse, true);
            if (temp == true) {
            this.startDrag();
            }
            }
            private function MU() {
            this.stopDrag();
            this._x =(Math.round(this._x / (this._width+10)))*(this._width+10);
            this._y =(Math.round(this._y / (this._height+10)))*(this._height+10);
            }
            }

            If you still know a better / different method please post also!
            • 3. Re: Class Question
              Level 7
              I think hitTest is the proper way, except you can shorten it up a bit:

              private function MD() {
              var temp:Boolean = this.hitTest(_root._xmouse, _root._ymouse, true);
              if (temp == true) {
              this.startDrag();
              }

              Why not just do:

              private function MD() {
              if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
              this.startDrag();
              }


              --
              Dave -
              Adobe Community Expert
              www.blurredistinction.com
              http://www.adobe.com/communities/experts/