On the Internet to see a game both drag and drop the MC and the MC, drag and drop with the mouse event to achieve, and rotation needs to use the shift+ mouse click event. It always feels too much trouble. So I hope I can find a way to pull and rotate at the same time with the mouse.
It turns out that mouse_down+mouse_up is equivalent to a click event. That is, each release of the left mouse button, stop dragging, the MC will rotate once, and this is obviously not the expected effect.
So, it begins to understand why the programmer added the SHIFT key to the listening.
But can't this function be implemented without the SHIFT key? I started thinking about how to distinguish mouse_down+mouse_up from click.
Method One: Set the time interval. Time is not very sure, pass away.
Method Two: Using the relative position of the mouse. If the MC is not moved, it is considered the click event. Positive Solution!
package{
Import Flash.display. *;
Import Flash.geom. Point;
Import flash.events.*;
public class Main extends sprite{
private Var mc:mc;
private Var Clickoffset:point;
private Var Mouseloc:point;
Public Function main () {
Mc=new MC ();
AddChild (MC);
mc.x=200;
mc.y=200;
Mc.addeventlistener (Mouseevent.click, rot);
Mc.addeventlistener (Mouseevent.mouse_down,startdrag);
Mc.addeventlistener (Event.enter_frame., drag);
Stage.addeventlistener (Mouseevent.mouse_up,stopdrag);
}
Private Function StartDrag (e:mouseevent) {
Mouseloc=new Point (E.stagex,e.stagey);
Clickoffset=new Point (E.STAGEX-MC.X,E.STAGEY-MC.Y);
}
Private Function Drag (e:event) {
if (clickoffset==null) return;
Mc.x=mousex-clickoffset.x;
Mc.y=mousey-clickoffset.y;
}
Private Function Stopdrag (e:mouseevent) {
Clickoffset=null;
}
Private function Rot (e:mouseevent) {
if (!mouseloc.equals (E.stagex,e.stagey)) return;
mc.rotation+=30;
}
}
}