2013-11-25 135 views
0

我有一些代码控制一个严重的图像产生和360旋转拖动mouseX轴时。这一切都适用于我用过的代码。舞台缩放影响AS3

因为我不得不针对不同的平台进行设计,并且在文档设置中放大了阶段的大小,我按比例调整了阶段复选框。

当鼠标向下时,旋转按预期方式精细地拖动图像,但是当您释放并开始再次拖动时,它不会记住最后一帧,并在再次拖动细线之前跳到另一帧。当我所做的一切都改变了一切的规模时,为什么它会像这样跳跃?

请参阅代码中使用

//ROTATION OF CONTROL BODY X 
spinX_mc.stop(); 

var spinX_mc:MovieClip; 
var offsetFrame:int = spinX_mc.currentFrame; 
var offsetX:Number = 0; 
var percent:Number = 0; 

//Listeners 
spinX_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging); 
spinX_mc.addEventListener(MouseEvent.MOUSE_UP, stopDragging); 

function startDragging(e:MouseEvent):void 
{ 

    // start listening for mouse movement 
    spinX_mc.addEventListener(MouseEvent.MOUSE_MOVE,drag); 
    offsetX = stage.mouseX; 
} 

function stopDragging(e:MouseEvent):void 
{ 
    ("stopDrag") 
    // STOP listening for mouse movement 
    spinX_mc.removeEventListener(MouseEvent.MOUSE_MOVE,drag); 
    // save the current frame number; 

    offsetFrame = spinX_mc.currentFrame; 

    removeEventListener(MouseEvent.MOUSE_DOWN, startDragging); 
} 

// this function is called continuously while the mouse is being dragged 

function drag(e:MouseEvent):void 
{ 
    trace ("Drag") 
    // work out how far the mouse has been dragged, relative to the width of the spinX_mc 
    // value between -1 and +1 
    percent = (mouseX - offsetX)/spinX_mc.width; 
    // trace(percent); 

    // work out which frame to go to. offsetFrame is the frame we started from 
    var frame:int = Math.round(percent * spinX_mc.totalFrames) + offsetFrame; 

    // reset when hitting the END of the spinX_mc timeline 
    while (frame > spinX_mc.totalFrames) 
    { 
     frame -= spinX_mc.totalFrames; 
    } 
    // reset when hitting the START of the spinX_mc timeline 
    while (frame <= 0) 
    { 
     frame += spinX_mc.totalFrames; 
    } 

    // go to the correct frame 
    spinX_mc.gotoAndStop(frame); 
} 

回答

0

通过改变

spinX_mc.addEventListener(MouseEvent.MOUSE_MOVE,drag); 
offsetX = stage.mouseX; 

spinX_mc.addEventListener(MouseEvent.MOUSE_MOVE,drag); 
offsetX = mouseX; 

我似乎解决了这个问题,一切顺利再次运行。