我在as3上创建了一个DragDrop类。我试图制作可移动的电影剪辑"坚持"到目标MovieClip。我已经获得了基本的拖拽和定位/坚持工作但是当我尝试创建一个"缓和"使用输入帧效果,不知何故,影片剪辑移动到0 x和y位置。
以下是正常工作的代码(没有EnterFrame事件)。
for cell in worksheet.get_cell_collection():
print(cell.value)
这里的代码不起作用(使用EnterFrame事件)。
package {
public class DragDrop {
public var clip:MovieClip;
public var targ:MovieClip;
public var myHomeX:Number;
public var myHomeY:Number;
public var myFinalX:Number;
public var myFinalY:Number;
public function selectClip(clipV:MovieClip,targV:MovieClip):void {
clip = clipV;
targ = targV;
var myHomeX = clip.x;
var myHomeY = clip.y;
var myFinalX = targ.x;
var myFinalY = targ.y;
clip.addEventListener(MouseEvent.MOUSE_DOWN,startDragging);
clip.addEventListener(MouseEvent.MOUSE_UP,stopDragging);
clip.addEventListener(MouseEvent.ROLL_OVER,rollOver);
clip.addEventListener(MouseEvent.ROLL_OUT,rollOut);
function startDragging(e:MouseEvent):void {
clip.startDrag();
clip.beingDragged = true;
clip.parent.setChildIndex(clip,clip.parent.numChildren - 1);
}
function stopDragging(e:MouseEvent):void {
clip.stopDrag();
clip.beingDragged = false;
var onTarget:MovieClip;
if (clip.dropTarget != null)
{
onTarget = e.target.dropTarget.parent;
}
else
{
onTarget = null;
}
if ((onTarget == targ))
{
clip.onTarget = true;
targ.gotoAndStop(2);
clip.x = myFinalX;
clip.y = myFinalY;
}
else
{
clip.onTarget = false;
targ.gotoAndStop(1);
clip.x = myHomeX;
clip.y = myHomeY;
}
}
function rollOver(e:MouseEvent) {
clipGlow.restart();
}
function rollOut(e:MouseEvent) {
clipGlow.reverse();
}
}
}
}
提前感谢您的帮助。 :)
答案 0 :(得分:0)
如果你这样做:
var myHomeX = clip.x;
var myHomeY = clip.y;
var myFinalX = targ.x;
var myFinalY = targ.y;
那么也许clip.myHomeX应该只是myHomeX等?
function slide(e:Event):void {
if (! clip.beingDragged && ! clip.onTarget)
{
clip.x -= clip.x -myHomeX / 5;
clip.y -= clip.y -myHomeY / 5;
clip.scaleX += (1 - clip.scaleX) / 5;
clip.scaleY += (1 - clip.scaleY) / 5;
}
else if (! clip.beingDragged && clip.onTarget)
{
clip.x -= clip.x -myFinalX / 5;
clip.y -= clip.y -myFinalY / 5;
clip.scaleX += (1.5 - clip.scaleX) / 5;
clip.scaleY += (1.5 - clip.scaleY) / 5;
}
}