简体   繁体   English

FLASH ActionScript 3.0问题

[英]FLASH actionscript 3.0 problems

I want to ask about this problem. 我想问这个问题。 I have a movieclip (instance name : char). 我有一个动画片段(实例名称:char)。 Inside it I have 2 frames. 在里面,我有两个框架。 The first frame contains a movieclip (it does nothing I forgot why I even bother to make it into movieclip). 第一帧包含一个动画片段(它什么都不做,我忘记了为什么我什至不愿意将它变成动画片段)。 This first frame has frame label "still". 该第一帧具有帧标签“静止”。

The second frame also contains a movieclip, inside it contains 12 frame. 第二帧还包含一个动画片段,内部包含12帧。 This second first frame has frame label "run" This is my code 第二个第一帧的帧标签为“ run”。这是我的代码

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");
    }
}

The problem is, when I press RIGHT ARROW button, It moves, but the movieclip (with frame name "run") can't loop or even play complete from frame 1-12, it only plays from frame 1-9 then stop (not go to frame 10 or even loop) is there something wrong with my code? 问题是,当我按向右箭头按钮时,它移动了,但是动画片段(帧名称为“ run”)无法循环播放,甚至无法从第1-12帧播放完成,它只能从第1-9帧播放然后停止(不去第10帧甚至循环)我的代码有问题吗?

Have a look at how often the KEY_DOWN-Event is actually fired. 看一下KEY_DOWN-Event实际触发的频率。 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. 实际上,您会重复调用gotoAndStop(“ run”),这会使您的动画mc始终保持重启状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM