Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3:单帧时间线中的重复功能_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 AS3:单帧时间线中的重复功能

Actionscript 3 AS3:单帧时间线中的重复功能,actionscript-3,flash,Actionscript 3,Flash,我对动作剧本很陌生。我有单帧时间线,有一个功能,移动垂直电影剪辑。我只想重复三次。 代码是有效的,我只是不确定这是正确的方法还是太复杂了 var pocet:Number = 0; pruh.addEventListener(Event.ENTER_FRAME, fl_AnimateVertically); function fl_AnimateVertically(event:Event) { if (pruh.y >= stage.stageHeight) { pocet+

我对动作剧本很陌生。我有单帧时间线,有一个功能,移动垂直电影剪辑。我只想重复三次。 代码是有效的,我只是不确定这是正确的方法还是太复杂了

var pocet:Number = 0;

pruh.addEventListener(Event.ENTER_FRAME, fl_AnimateVertically);

function fl_AnimateVertically(event:Event)
{
if (pruh.y >= stage.stageHeight) {
    pocet++;
}
if (pruh.y < stage.stageHeight) {
pruh.y += 3;
}
else {
    pruh.y = 0 - pruh.y;
}
if (pocet == 3) {
    pruh.removeEventListener(Event.ENTER_FRAME, fl_AnimateVertically);
}
}
var-pocet:Number=0;
pruh.addEventListener(Event.ENTER\u FRAME,fl\u动画);
函数fl_动画化(事件:事件)
{
if(pruh.y>=舞台高度){
pocet++;
}
if(pruh.y<阶段高度){
pruh.y+=3;
}
否则{
pruh.y=0-pruh.y;
}
如果(pocet==3){
pruh.removeEventListener(Event.ENTER_FRAME,fl_animatively);
}
}
thanx试试这个

var-pocet:Number=0;
pruh.addEventListener(Event.ENTER\u FRAME,fl\u动画);
变量startY:int=pruh.y;
函数fl_动画化(事件:事件)
{
if(pruh.y>=舞台高度){
pocet++;
pruh.y=星形;
}
if(pruh.y<阶段高度){
pruh.y+=3;
}
否则{
pruh.y=0-pruh.y;
}
如果(pocet==3){
pruh.removeEventListener(Event.ENTER_FRAME,fl_animatively);
跟踪(“完成”);
}

}
祝贺你实现了目标

您的代码在可读性方面可以得到改进。你可以用
fl\u作为一个描述性的名字,但除此之外,很难准确地理解到底发生了什么。我的意思是,它肯定会给y加上3,这可能会导致运动,但要理解确切的行为并不容易

这就是为什么您希望使用抽象或更多的自上而下的方法。。 此时您正在做的是向坐标添加值,从而创建动画。你真正想要的是创建一个动画,而不需要详细说明这实际上意味着什么

果然,人们以前用代码制作过动画。这就是为什么可以创建抽象意义上的动画:动画是对象属性随时间的变化

让我们以这里的示例代码为例:

var myTween:Tween = new Tween(myObject, "x", Elastic.easeOut, 0, 300, 3, true);
并将其应用于你的情况

var verticalAnimation:Tween = new Tween(pruh, "y", Elastic.easeOut, pruh.y, stage.stageHeight, 3, true);
你必须根据自己的喜好调整持续时间。我希望您看到这是如何更容易阅读和维护的,因为您指定了动画的属性,如持续时间。还可以指定缓和,这会使运动更有趣

好的,这只是一个动画,但是你想要3个,对吗? 更准确地说,您希望在动画完成后再次执行相同的动画。 你可以做到这一点:

var animationCount:uint = 0;
var verticalAnimation:Tween = new Tween(pruh, "y", Elastic.easeOut, pruh.y, stage.stageHeight, 3, true);

verticalAnimation.addEventListener(TweenEvent.MOTION_FINISH, onMotionFinish); // wait for the animation to be finished

function onMotionFinish(e:TweenEvent):void
{
    animationCount++; // add 1 to the counter

    if(animationCount >= 3)  // check how many times the animation finished so far
    {
        // if it was the last one, remove the listener
        verticalAnimation.removeEventListener(TweenEvent.MOTION_FINISH, onMotionFinish);
    }
    else
    {
        // otherwise rewind and start again
        verticalAnimation.rewind();
        verticalAnimation.start();
    }
}
除了这个内置的
Tween
类之外,还有其他库功能更强大。 你可以