Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Sprite.html#startDrag%28%29" rel="nofollow">startDrag()</a> has a <code>lockCenter</code> argument which you could try playing with.</p> <blockquote> <p><strong><code>lockCenter:Boolean</code></strong> (default = <code>false</code>) — Specifies whether the draggable sprite is locked to the center of the mouse position (<code>true</code>), or locked to the point where the user first clicked the sprite (<code>false</code>).</p> </blockquote> <hr> <h2>Without startDrag as per comment</h2> <hr> <p>Make this the base class of an object that you want to drag:</p> <pre><code>package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.events.Event; public class Draggable extends Sprite { // vars private var _hx:Number = 0; private var _hy:Number = 0; /** * Constructor */ public function Draggable() { addEventListener(MouseEvent.MOUSE_DOWN, _mouseDown); } /** * MouseEvent.MOUSE_DOWN */ private function _mouseDown(e:MouseEvent):void { _hx = mouseX; _hy = mouseY; addEventListener(Event.ENTER_FRAME, _handle); addEventListener(MouseEvent.MOUSE_UP, _mouseUp); } /** * MouseEvent.MOUSE_UP */ private function _mouseUp(e:MouseEvent):void { removeEventListener(Event.ENTER_FRAME, _handle); removeEventListener(MouseEvent.MOUSE_UP, _mouseUp); } /** * Event.ENTER_FRAME */ private function _handle(e:Event):void { x = parent.mouseX - _hx; y = parent.mouseY - _hy; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload