4 Replies Latest reply on Mar 8, 2007 3:34 AM by phil ashby

    Turn StartDrag On & Off

    phil ashby Level 1
      Hi guys and gals,

      I've got an app that creates several instance from a database and displays them on the screen (images, text, video etc). Each element has it's own name/instancename and is listed in a listbox. I want the user to be able to select the element from the listbox and click a "move" button, which will attach the appropriate startDrag/ stopDrag code onto the relevant element (movieclip). I can attach the code upon creation of the clip eg

      evt.onPress = function() {
      evt.startDrag(false,40,90,890,690);
      };
      evt.onRelease = function() {
      evt.stopDrag();
      };

      but is there a way to disable this until the user presses the move button. Alternatively, is there a may to "attach" the code to the movieclip as and when it's required and then detach it once the move has finished?

      thanks all!
        • 1. Re: Turn StartDrag On & Off
          Level 7
          phil ashby,

          >I can attach the code upon creation of the clip eg
          >
          > evt.onPress = function() {
          > evt.startDrag(false,40,90,890,690);
          > };

          Let's take a look so far. (I'm assuming "evt" the instance name of your
          clip.) It makes more sense at this point to use the global "this" property
          inside the function assigned to evt's MovieClip.onPress event.

          evt.onPress = function():Void {
          this.startDrag(false,40,90,890,690);
          }

          > evt.onRelease = function() {
          > evt.stopDrag();
          > };

          Same thing here.

          > but is there a way to disable this until the user presses
          > the move button.

          Sure thing. :) Check out the MovieClip class entry of the ActionScript
          2.0 Language Reference for all the things you can do with a movie clip
          symbol. Among the property, method, and event categories, you'll find a
          MovieClip._enabled property.

          > Alternatively, is there a may to "attach" the code to
          > the movieclip as and when it's required and then
          > detach it once the move has finished?

          There is. In fact, you've already accomplished half of this goal: by
          virtue of your existing ActionScript, you've already "attached" code to an
          instance. You'll have to handle the appropriate change or release event for
          your list box (see the Components Language Reference for event information)
          and cause that event handler to invoke the same ActionScript you've already
          shown.

          If you prefer -- and this may make things a bit easier -- use a named
          function instead of a function literal:

          function customStartDrag():Void {
          this.startDrag(false,40,90,890,690);
          }
          function customStopDrag():Void {
          this.stopDrag();
          }

          evt.onPress = customStartDrag;
          evt.onRelease = customStopDrag;
          evt.onReleaseOutside = customStopDrag;

          And to remove ...

          evt.onPress = null;
          evt.onRelease = null;
          evt.onReleaseOutside = null;


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Turn StartDrag On & Off
            phil ashby Level 1
            Hi David,

            thanks for that. I've added the relevant code and it works fine, except for one thing. When I "remove" the onpress/release functions from the clip by setting them to null, it's not truely removing them, as I still get the finger pointer...

            I guess I can get round it by setting useHandCursor=false but I was wondering if there is a cleaner method of achieving this?

            • 3. Re: Turn StartDrag On & Off
              Level 7
              phil ashby,

              > When I "remove" the onpress/release functions from the
              > clip by setting them to null, it's not truely removing them,
              > as I still get the finger pointer...

              Makes you wanna *give* the finger, eh? ;) I think your solution, of
              setting the useHandCursor property to false, is good. Sure, it's an extra
              step, but certainly not hacky (in the negative sense) or dirty.

              If memory serves me, the finger issue is possibly avoidable if you
              delete the function reference rather than setting it to null -- but test,
              please, because I don't remember for sure.

              // instead of ...
              evt.onPress = null;

              // ... try
              delete evt.onPress;


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."


              • 4. Re: Turn StartDrag On & Off
                phil ashby Level 1
                Yep, delete does the trick.

                Thanks again David