Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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
Flash 闪存AS3定时器问题_Flash_Actionscript 3_Animation_Loops_Timer - Fatal编程技术网

Flash 闪存AS3定时器问题

Flash 闪存AS3定时器问题,flash,actionscript-3,animation,loops,timer,Flash,Actionscript 3,Animation,Loops,Timer,我有一个timerEvent,它在舞台上增加了25个电影嘴唇,并从x:0,y:0开始制作动画,这一切都很好!我想做的是为每个电影剪辑指定一个y值,比添加到舞台上的最后一个电影剪辑多25像素。我做了一个小测试,每次定时器做循环时,我都试图增加一个数值,但它没有增加。我也应该使用for循环/数组吗 提前谢谢。 乔诺 没有找到您试图增加变量或向y添加25px的部分,但请尝试以下操作: function itemTimer_tick(e:TimerEvent):void { ...

我有一个timerEvent,它在舞台上增加了25个电影嘴唇,并从x:0,y:0开始制作动画,这一切都很好!我想做的是为每个电影剪辑指定一个y值,比添加到舞台上的最后一个电影剪辑多25像素。我做了一个小测试,每次定时器做循环时,我都试图增加一个数值,但它没有增加。我也应该使用for循环/数组吗

提前谢谢。 乔诺


没有找到您试图增加变量或向y添加25px的部分,但请尝试以下操作:

function itemTimer_tick(e:TimerEvent):void {

    ...

    mc.y = itemTimer.currentCount * 25;
    addChild(mc);

    ...

}

我真正不同的方法是使用
Tweener.addTween
方法的
delay
属性。启动所有movieclips,并将每个movieclips的延迟增加一点点?

老实说,我本来会先用for循环来设置这一切的。完成for循环后,相应地放置每个项目,然后使用TweenLite或您最喜欢的Tweening软件包

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    import gs.TweenLite;
    import gs.easing.*;

    public class ExampleDocumentClass extends Sprite
    {
        if(stage) _init();
        else addEventListener(Event.ADDED_TO_STAGE, _init(), false, 0, true);
    }
    private function _init(e:Event =null):void
    {
        for(var i:int = 0; i < 25; i++)
        {
            var mc:MovieClip = new MovieClip();
            mc.graphics.beginFill(Math.random() * 0x000000);
            mc.graphics.drawRect(0,0,stage.stageWidth,25);
            //Seperates them by 25, their width, so they will touch.
            mc.x= i * 25; //i * 25 + 1 leaves a space in between.
            mc.y=0;
            addChild(mc);
            TweenLite.to(mc, 0.9, {y:math.random()*1000-500, x: 0, ease: Expo.easeOut});

        if(i == 24) //Total length - 1
        {
            //The loop ended.
        }
    }
}
包
{
导入flash.display.Sprite;
导入flash.events.Event;
进口gs.TweenLite;
进口一般商品;
公共类ExampleDocumentClass扩展了Sprite
{
if(stage)_init();
else addEventListener(Event.ADDED_TO_STAGE,_init(),false,0,true);
}
私有函数_init(e:Event=null):void
{
对于(变量i:int=0;i<25;i++)
{
var mc:MovieClip=新的MovieClip();
mc.graphics.beginll(Math.random()*0x000000);
mc.graphics.drawRect(0,0,stage.stageWidth,25);
//将它们分开25,它们的宽度,因此它们会接触。
mc.x=i*25;//i*25+1在两者之间留下一个空格。
mc.y=0;
addChild(mc);
to(mc,0.9,{y:math.random()*1000-500,x:0,ease:Expo.easeOut});
if(i==24)//总长度-1
{
//循环结束了。
}
}
}
需要注意的是,屏幕更新不会发生在代码块内,例如for和while循环。您不能以我所展示的方式将这些代码块彼此隔开,因为即使前面的项目x可能刚刚设置好,它也没有被绘制到屏幕上;为了构建一个系统,比如说所有图像都不是ame width,但是必须一个接一个地启动,我们必须等待Event.COMPLETE事件为给定的加载程序触发,以便我们可以访问它的宽度和其他属性。因为您只想将它们间隔25像素,并且它们的大小相同,所以我们仅使用“i”来分隔它们

发生了什么: i*25=0; i++; i*25=25; i++; i*25=50

正如你所看到的,我们已经达到了我们想要的间距

布莱恩·霍奇

使用以下方法:

 import flash.events.*;
 import caurina.transitions.*;

bringItemsOn();

var extra:int = 0;
var itemTimer:Timer;
function bringItemsOn():void {
    itemTimer=new Timer(300);
    itemTimer.addEventListener(TimerEvent.TIMER,itemTimer_tick);
    itemTimer.start();
}

function itemTimer_tick(e:TimerEvent):void {    
    itemTimer.currentCount-1;
    var mc:MovieClip = new MovieClip();
    mc.graphics.beginFill(Math.random() * 0x000000);
    mc.graphics.drawRect(0,0,stage.stageWidth,25);
    mc.x += extra;
    mc.y=0;
    extra = mc.width;
 /*u can use mc's width for different x value's or

make ur own like extra += 10; each mc.x will be different */
    addChild(mc);
    Tweener.addTween(mc,{y:Math.random()*1000 - 500,
                             x:0,
                             time:.9,
                             transition:"easeOutExpo"});

    if (itemTimer.currentCount>=25) {
        itemTimer.removeEventListener(TimerEvent.TIMER,itemTimer_tick);
    }
}

Tweener.addTween(mc,{y:mc.y+50,x:0,time:.9,transition:“easeOutExpo”});如果我添加/使用for循环,我可以引用每个对象并分配mc[i]+50,所以我想知道是否可以集成toThanks dude!这就是我使用currentCount*jobbie作为var-var-mcFinal:Number=(itemTimer.currentCount*50);Tweener.addTween(mc,{y:mcFinal,x:0,时间:.9,转换:“easeOutExpo”});这就解决了!非常感谢!你知道,如果答案可以接受的话,你也应该接受:)哦,对不起,这是一个很好的方法!同时使所有对象都易于访问,引用点击事件等…谢谢!当然,在使用for循环的情况下,我只会将延迟设置为i*delay差别。
 import flash.events.*;
 import caurina.transitions.*;

bringItemsOn();

var extra:int = 0;
var itemTimer:Timer;
function bringItemsOn():void {
    itemTimer=new Timer(300);
    itemTimer.addEventListener(TimerEvent.TIMER,itemTimer_tick);
    itemTimer.start();
}

function itemTimer_tick(e:TimerEvent):void {    
    itemTimer.currentCount-1;
    var mc:MovieClip = new MovieClip();
    mc.graphics.beginFill(Math.random() * 0x000000);
    mc.graphics.drawRect(0,0,stage.stageWidth,25);
    mc.x += extra;
    mc.y=0;
    extra = mc.width;
 /*u can use mc's width for different x value's or

make ur own like extra += 10; each mc.x will be different */
    addChild(mc);
    Tweener.addTween(mc,{y:Math.random()*1000 - 500,
                             x:0,
                             time:.9,
                             transition:"easeOutExpo"});

    if (itemTimer.currentCount>=25) {
        itemTimer.removeEventListener(TimerEvent.TIMER,itemTimer_tick);
    }
}