0

我想问一下这个问题。我有一个影片剪辑(实例名称:char)。在里面我有2个框架。第一帧包含一个movieclip(它什么也没做,我忘记了为什么我还要费心把它做成movieclip)。这第一帧具有帧标签“静止”。

第二帧还包含一个影片剪辑,其中包含 12 帧。第二个第一帧有帧标签“运行”这是我的代码

char.gotoAndStop(char.still);

stage.addEventListener(KeyboardEvent.KEY_DOWN, keysDown);
stage.addEventListener(KeyboardEvent.KEY_UP,keysUp);


function keysDown(e:KeyboardEvent):void{
    if(e.keyCode == Keyboard.RIGHT)
    {       
        char.gotoAndStop("run");
        this. char.scaleX = 1;
    }   
}

function keysUp(e:KeyboardEvent):void{
    if(e.keyCode == Keyboard.RIGHT)
    {
        char.gotoAndStop("still");
    }
}

问题是,当我按下右箭头按钮时,它会移动,但影片剪辑(帧名称为“run”)无法循环播放,甚至无法从第 1-12 帧完整播放,它只能从第 1-9 帧播放然后停止(不要转到第 10 帧甚至循环)我的代码有问题吗?

4

1 回答 1

0

Have a look at how often the KEY_DOWN-Event is actually fired. For example by just tracing.

function keysDown(e:KeyboardEvent):void{
    if(e.keyCode == Keyboard.RIGHT)
    {       
        trace("pressed");
        char.gotoAndStop("run");
        this. char.scaleX = 1;
    }   
}

You will realize that the event is thrown WHILE the Key is pressed, not only once. You actually call the gotoAndStop("run") repeatedly, which makes your animation mc restart all the time.

于 2012-08-30T08:10:22.213 回答