我有两个按钮可以在 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");
}