动作脚本3,在拖动下旋转对象
|
我有一个对象,需要通过单击和拖动来旋转。遵循一些AS2代码,每次单击鼠标时,我都会使对象旋转一点,但不能使其与拖动一起工作。
needle.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_2);
function fl_ClickToDrag_2(event:MouseEvent):void
{
var angle = Math.atan2(mouseY-needle.y,mouseX-needle.x);
// apply rotation to handle by converting angle into degrees
needle.rotation = angle*180/Math.PI;
// rotate the grip opposite the handle so it won\'t rotate along with it
//this.grip._rotation = -this._rotation;
}
function fl_ReleaseToDrop_2(event:MouseEvent):void
{
needle.stopDrag();
}
没有找到相关结果
已邀请:
1 个回复
喷乡顾沥沪
事件每次单击仅触发一次,因此您只在处理程序中运行一次代码。 可能有比这更好的方法,但这就是我考虑的方式: 编辑的详细信息:
因此,当用户单击(
)时,它会激活一个事件侦听器,该事件侦听器在每次鼠标移动时都会触发
处理程序。当用户放开单击时,事件侦听器将被销毁。添加事件侦听器时的ѭ5表示使它成为弱引用的侦听器,以便由垃圾回收器收集它,而不仅仅是坐在内存中永久占用空间。