3 Replies Latest reply on Apr 18, 2006 7:17 PM by Rothrock

    Unabe to get startDrag to work as desired

    Jadeivy
      O.k. - Issue...

      I want to confine this to a menu area of the screen...

      myMovieClip.onEnterFrame = function () {
      startDrag(this,true,20,0,300,0);
      };

      This actually ruins all other mouse funcitons on the screen and provides an error:

      **Error** Symbol=InterfaceMain, layer=MouseConst, frame=1:Line 3: Statement must appear within on/onClipEvent handler
      };

      Total ActionScript Errors: 1 Reported Errors: 1

      Any ideas?

      The goal is to confine the mouse drag to a specific mc on the main screen. - While maintaining other button functionality..
        • 1. Unabe to get startDrag to work as desired
          DuhChamp
          Try this...

          myMovieClip.onPress = function()
          {
          startDrag(whatever ur parameters);
          }

          and then

          myMovieClip.onRelease = function()
          {
          stopDrag();
          }
          • 2. Re: Unabe to get startDrag to work as desired
            Jadeivy Level 1
            This still does not allow me to use other buttons around the drag.

            The menu is a horizontal list of four link areas.

            I want the user to be able to click each link independent.

            The drag would just place a magnifying glass over the link (with the user having the ability to click through to link).
            The magnifying glass would move with the mouse from one link to the next (constrained in the x axis via 50,0,400,0).


            Thanks though...
            • 3. Re: Unabe to get startDrag to work as desired
              Rothrock Level 5
              There are actually at least two things going wrong here. DuhChamp's solution will help with part of it, but not the whole story.

              There are two main ways to make clips/buttons do things. One way is to put the code directly onto the instance. You do this by selecting the instance and then opening the actionscript panel.

              The other way is to put the code on a frame and use the instance name to reference the code to the instance.

              When you put the code on the instance, every command must appear inside of an on/onClipEvent handler. This is what the error message is telling you – that you have put the code directly on the instance InterfaceMain, but the code wasn't wrapped with the correct on/onClip event. An example would be:

              on( enterFrame ){
              //do something here
              }

              And that leads to the second problem. onEnterFrame seems to cause new folks a lot of grief. It doesn't mean "do this code upon the playhead entering this frame" it means "repeat this bit of code over and over at the swf file's frame rate, repeat forever until this onEnterFrame is killed." It will repeat even if your timeline is stopped or if the movie has only one frame.

              I don't think you want to startDrag 21 times a second (or whatever your framerate is.)

              Generally people want to drag when something is clicked. So something like

              on(press){
              this.startDrag(values);
              }

              is much more probable. However the approach of putting code directly upon the instances is a bit old-school. It means you will have some code scattered here, some there, and always some that you just can't seem to find! By putting the code on frames it makes it easier to have all your code in one place. In that case you would most likely want to use something like DuhChamp has suggested.