如何使用按钮在Y轴上停止动画片段?

时间:2012-06-11 11:42:21

标签: actionscript-3 boundary

我有两个按钮可以在Y轴上/下移动动画片段。如何让动画片段在某个高度停止,并且仍然可以向相反方向移动?

我需要这样工作:

按下向下按钮时,动画片段会向下移动,但不会超过Y = 500。 当您按下向上按钮时,动画片段会向上移动,但不会超过Y = 300。

我让movieclip停在正确的位置(500),但是当它到达这一点时它会卡住.. 所以如果我按下按钮,它就不会再次上升。

有人可以帮助我吗?:)

到目前为止,这是我的代码:

1) decrease = the down-button
2) increase = up-button
3) stempel = the movieclip I want to stop on the Y-axis



var moveStempel = 0;

decrease.addEventListener(MouseEvent.MOUSE_DOWN, decreasePressed);  
decrease.addEventListener(MouseEvent.MOUSE_UP, removeEnterFrame);

increase.addEventListener(MouseEvent.MOUSE_DOWN, increasePressed); 
increase.addEventListener(MouseEvent.MOUSE_UP, removeEnterFrame);

function decreasePressed(e:MouseEvent):void  
{   
    moveStempel = 2;
    addEnterFrame();
}


function increasePressed(e:MouseEvent):void  
{   
    moveStempel = -2;
    addEnterFrame();
}




// ADD ENTER FRAME 
function addEnterFrame():void 
{     
    this.addEventListener(Event.ENTER_FRAME, update); 
}  

function removeEnterFrame(e:MouseEvent):void 
{     
    this.removeEventListener(Event.ENTER_FRAME, update); 
}  

function update(e:Event):void 
{     
    if (stempel.y < 500)
    {
        stempel.y += moveStempel;
        trace("inside");
    }

    else if (stempel.y > 500)
    {
        stempel.stop();
        trace("outside");
    }

1 个答案:

答案 0 :(得分:0)

现在,在您的代码中,stempel的{​​{1}}值大于500后,它将永远无法再次移动。

y可以移动时有两个条件:如果它向下移动,它不能位于允许区域的底部,如果它向上移动,则它不能位于允许的区域。

stempel