4 Replies Latest reply on Oct 12, 2007 3:04 PM by kglad

    Drag Movie Clip AND Change Cursor

    bcmpro
      Is there an alternative method of changing the cursor icon other than using startDrag/hidecursor? I have a swf that uses stopDrags for a another movie clip, and obviously whenever the stopDrag script is called the cursor stops following. Any ideas?
        • 1. Re: Drag Movie Clip AND Change Cursor
          kglad Adobe Community Professional & MVP
          you don't need to use startDrag(). you can use a loop that repeatedly assigns your custom cursor's position to be the same as the mouse position.
          • 2. Re: Drag Movie Clip AND Change Cursor
            Level 7
            bcmpro,

            > Is there an alternative method of changing the cursor icon
            > other than using startDrag/hidecursor?

            Sure thing. All it takes, is to set the cursor's x and y coordinates to
            the mouse's on some sort of repeating loop, such as MovieClip.onEnterFrame
            or setInterval() in ActionScript 2.0 or Event.ENTER_FRAME or the Timer class
            in ActionScript 3.0.

            > I have a swf that uses stopDrags for a another movie clip,
            > and obviously whenever the stopDrag script is called the
            > cursor stops following. Any ideas?

            Understood; makes perfect sense. Here's a brief article that shows my
            above suggestion in a slightly different way. It's definitely more complex
            than you're asking for, but the same mechanism applies.

            http://www.quip.net/blog/2006/flash/actionscript-20/how-to-constrain-circle

            In that article, the "dragging" loop is based on the
            MovieClip.onMouseMove event in ActionScript 2.0. The article goes into some
            detail explaining the process, but here's a quick sample. The following
            assumes your "cursor" movie clip has the instance name mcCursor.

            mcCursor.onEnterFrame = function():Void {
            this._x = _root._xmouse;
            this._y = _root._ymouse;
            }

            That's a simple MovieClip.onEnterFrame approach. A function is assigned
            to the MovieClip.onEnterFrame event of the mcCursor movie clip. The
            function sets the MovieClip._x and the MovieClip._y properties of that clip
            to the corresponding properties of the main timeline's mouse. The main
            timeline (here referenced by _root) is, in fact, a movie clip, which is why
            a reference to it supports MovieClip class properties.

            That preceding example is only as good as your framerate. In
            low-framerate movies, the "cursor" will jitter a bit. The setInterval()
            approach might better suit your needs, because setInterval() allows for the
            updateAfterEvent() function, which updates the screen immediately, rather
            that once every frame:

            setInterval(
            function():Void {
            mcCursor._x = _root._xmouse;
            mcCursor._y = _root._ymouse;
            updateAfterEvent();
            }, 33
            );

            The setInterval() function takes two parameters: a) a function to
            repeat and b) the time interval in which to repeat it (here, 33
            milliseconds).

            setInterval(functionToPerform, whenToPerform);

            In the above, the function slot gets this:

            function():Void {
            mcCursor._x = _root._xmouse;
            mcCursor._y = _root._ymouse;
            updateAfterEvent();
            }

            ... while the time slot gets 33.


            David Stiller
            Co-author, Foundation Flash CS3 for Designers
            http://tinyurl.com/2k29mj
            "Luck is the residue of good design."


            • 3. Re: Drag Movie Clip AND Change Cursor
              bcmpro Level 1
              You guys are great, thank you
              • 4. Re: Drag Movie Clip AND Change Cursor
                kglad Adobe Community Professional & MVP
                you're welcome.