0

这是我在我的主机上的代码。我需要页面只从上到下读取代码 3 次。即使你能想到我怎么做才能让它停止 45 秒。对不起,我脑死了,不能再思考了。有什么建议吗?

import com.greensock.*;
import com.greensock.easing.*;

import flash.utils.*;

function doStuff() {

    //startValues
    box1.back.rotationY = -90;
    box1.back.alpha=0;

    var flipSpeed:Number = .25; 
    var flipSpeedbea:Number = .04; 

    var tl:TimelineMax = new TimelineMax({delay:2});
    tl.append(TweenMax.to(box1.front, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    tl.append(TweenMax.to(box1.back, 0, {alpha:1, immediateRender:false}))
    tl.append(TweenMax.to(box1.back, flipSpeed, {rotationY:0, ease:Linear.easeNone}))
    tl.append(TweenMax.to(box1.front, flipSpeed, {rotationY:0, visible:true, ease:Linear.easeNone}))
    var tb:TimelineMax = new TimelineMax({delay:4});

    box2.back2.rotationY = -90;
    box2.back2.alpha=0;

    tb.append(TweenMax.to(box2.front2, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    tb.append(TweenMax.to(box2.back2, 0, {alpha:1, immediateRender:false}))
    tb.append(TweenMax.to(box2.back2, flipSpeed, {rotationY:0, ease:Linear.easeNone}))
    tb.append(TweenMax.to(box2.front2, flipSpeed, {rotationY:0, visible:true, ease:Linear.easeNone}))

    var ins:TimelineMax = new TimelineMax({delay:6});

    box3.back3.rotationY = -90;
    box3.back3.alpha=0;

    ins.append(TweenMax.to(box3.front3, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    ins.append(TweenMax.to(box3.back3, 0, {alpha:1, immediateRender:false}))
    ins.append(TweenMax.to(box3.back3, flipSpeed, {rotationY:0, ease:Linear.easeNone}))
    ins.append(TweenMax.to(box3.front3, flipSpeed, {rotationY:0, visible:true, ease:Linear.easeNone}))

    var per:TimelineMax = new TimelineMax({delay:7});

    person.back_person.rotationY = -90;
    person.back_person.alpha=0;

    per.append(TweenMax.to(person.front_person, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    per.append(TweenMax.to(person.back_person, 0, {alpha:1, immediateRender:false}))
    per.append(TweenMax.to(person.back_person, flipSpeed, {rotationY:0, ease:Linear.easeNone}));

    var bea:TimelineMax = new TimelineMax({delay:7});

    be_a.bea_back.rotationY = -90;
    be_a.bea_back.alpha=0;

    bea.append(TweenMax.to(be_a.bea_front, flipSpeedbea, {rotationY:90, visible:false, ease:Linear.easeNone}))
    bea.append(TweenMax.to(be_a.bea_back, 0, {alpha:1, immediateRender:false}))
    bea.append(TweenMax.to(be_a.bea_back, flipSpeedbea, {rotationY:0, ease:Linear.easeNone}));
    bea.append(TweenMax.to(be_a.bea_front, flipSpeedbea, {rotationY:0, visible:true, ease:Linear.easeNone}))

    stop();

    setTimeout(doStuff, 15000);
}

doStuff();

是否可以在 doStuff 上设置一个函数以仅继续运行 45 秒?基本上我需要功能“doStuff”以每次 15 秒播放 3 次。

4

2 回答 2

0

如果您想调用doStuff3 次,间隔 15 秒,请setTimeout从内部删除对 的调用doStuff,然后执行以下操作:

var stuffTimer:Timer = new Timer(15000, 2);
stuffTimer.addEventListener(TimerEvent.TIMER, doStuff)
doStuff(null);
stuffTimer.start();

您需要更改doStuff方法以接受 TimerEvent:

function doStuff(e:TimerEvent):void
{
    [...]
}

无关,您应该将您的导入移出doStuff方法并将它们与您的第一个导入语句组合在一起。

于 2013-03-18T21:26:09.877 回答
0

第一个解决方案是使用变量作为计数器,这样您就不需要使用 Timer:

import com.greensock.*;
import com.greensock.easing.*;

import flash.utils.*;

var box1:Object;
var box2:Object;
var box3:Object;
var person:Object;
var be_a:Object;

function stop() {}

var stuffCount:uint = 0;

function doStuff() {

    stuffCount++;

    //startValues
    box1.back.rotationY = -90;
    box1.back.alpha=0;

    var flipSpeed:Number = .25; 
    var flipSpeedbea:Number = .04; 

    var tl:TimelineMax = new TimelineMax({delay:2});
    tl.append(TweenMax.to(box1.front, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    tl.append(TweenMax.to(box1.back, 0, {alpha:1, immediateRender:false}))
    tl.append(TweenMax.to(box1.back, flipSpeed, {rotationY:0, ease:Linear.easeNone}))
    tl.append(TweenMax.to(box1.front, flipSpeed, {rotationY:0, visible:true, ease:Linear.easeNone}))
    var tb:TimelineMax = new TimelineMax({delay:4});

    box2.back2.rotationY = -90;
    box2.back2.alpha=0;

    tb.append(TweenMax.to(box2.front2, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    tb.append(TweenMax.to(box2.back2, 0, {alpha:1, immediateRender:false}))
    tb.append(TweenMax.to(box2.back2, flipSpeed, {rotationY:0, ease:Linear.easeNone}))
    tb.append(TweenMax.to(box2.front2, flipSpeed, {rotationY:0, visible:true, ease:Linear.easeNone}))

    var ins:TimelineMax = new TimelineMax({delay:6});

    box3.back3.rotationY = -90;
    box3.back3.alpha=0;

    ins.append(TweenMax.to(box3.front3, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    ins.append(TweenMax.to(box3.back3, 0, {alpha:1, immediateRender:false}))
    ins.append(TweenMax.to(box3.back3, flipSpeed, {rotationY:0, ease:Linear.easeNone}))
    ins.append(TweenMax.to(box3.front3, flipSpeed, {rotationY:0, visible:true, ease:Linear.easeNone}))

    var per:TimelineMax = new TimelineMax({delay:7});

    person.back_person.rotationY = -90;
    person.back_person.alpha=0;

    per.append(TweenMax.to(person.front_person, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    per.append(TweenMax.to(person.back_person, 0, {alpha:1, immediateRender:false}))
    per.append(TweenMax.to(person.back_person, flipSpeed, {rotationY:0, ease:Linear.easeNone}));

    var bea:TimelineMax = new TimelineMax({delay:7});

    be_a.bea_back.rotationY = -90;
    be_a.bea_back.alpha=0;

    bea.append(TweenMax.to(be_a.bea_front, flipSpeedbea, {rotationY:90, visible:false, ease:Linear.easeNone}))
    bea.append(TweenMax.to(be_a.bea_back, 0, {alpha:1, immediateRender:false}))
    bea.append(TweenMax.to(be_a.bea_back, flipSpeedbea, {rotationY:0, ease:Linear.easeNone}));
    bea.append(TweenMax.to(be_a.bea_front, flipSpeedbea, {rotationY:0, visible:true, ease:Linear.easeNone}))

    stop();

    if (stuffCount < 3)
    {
        setTimeout(doStuff, 15000);
    }
}

doStuff();

第二种解决方案Timer

import com.greensock.;
import com.greensock.easing.*;

import flash.events.TimerEvent;
import flash.utils.*;


function doStuff() {

    //startValues
    box1.back.rotationY = -90;
    box1.back.alpha=0;

    var flipSpeed:Number = .25; 
    var flipSpeedbea:Number = .04; 

    var tl:TimelineMax = new TimelineMax({delay:2});
    tl.append(TweenMax.to(box1.front, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    tl.append(TweenMax.to(box1.back, 0, {alpha:1, immediateRender:false}))
    tl.append(TweenMax.to(box1.back, flipSpeed, {rotationY:0, ease:Linear.easeNone}))
    tl.append(TweenMax.to(box1.front, flipSpeed, {rotationY:0, visible:true, ease:Linear.easeNone}))
    var tb:TimelineMax = new TimelineMax({delay:4});

    box2.back2.rotationY = -90;
    box2.back2.alpha=0;

    tb.append(TweenMax.to(box2.front2, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    tb.append(TweenMax.to(box2.back2, 0, {alpha:1, immediateRender:false}))
    tb.append(TweenMax.to(box2.back2, flipSpeed, {rotationY:0, ease:Linear.easeNone}))
    tb.append(TweenMax.to(box2.front2, flipSpeed, {rotationY:0, visible:true, ease:Linear.easeNone}))

    var ins:TimelineMax = new TimelineMax({delay:6});

    box3.back3.rotationY = -90;
    box3.back3.alpha=0;

    ins.append(TweenMax.to(box3.front3, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    ins.append(TweenMax.to(box3.back3, 0, {alpha:1, immediateRender:false}))
    ins.append(TweenMax.to(box3.back3, flipSpeed, {rotationY:0, ease:Linear.easeNone}))
    ins.append(TweenMax.to(box3.front3, flipSpeed, {rotationY:0, visible:true, ease:Linear.easeNone}))

    var per:TimelineMax = new TimelineMax({delay:7});

    person.back_person.rotationY = -90;
    person.back_person.alpha=0;

    per.append(TweenMax.to(person.front_person, flipSpeed, {rotationY:90, visible:false, ease:Linear.easeNone}))
    per.append(TweenMax.to(person.back_person, 0, {alpha:1, immediateRender:false}))
    per.append(TweenMax.to(person.back_person, flipSpeed, {rotationY:0, ease:Linear.easeNone}));

    var bea:TimelineMax = new TimelineMax({delay:7});

    be_a.bea_back.rotationY = -90;
    be_a.bea_back.alpha=0;

    bea.append(TweenMax.to(be_a.bea_front, flipSpeedbea, {rotationY:90, visible:false, ease:Linear.easeNone}))
    bea.append(TweenMax.to(be_a.bea_back, 0, {alpha:1, immediateRender:false}))
    bea.append(TweenMax.to(be_a.bea_back, flipSpeedbea, {rotationY:0, ease:Linear.easeNone}));
    bea.append(TweenMax.to(be_a.bea_front, flipSpeedbea, {rotationY:0, visible:true, ease:Linear.easeNone}))

    stop();
}

function onTimer(event:TimerEvent):void
{
    doStuff();
}

var myTimer:Timer = new Timer(15000, 3);
myTimer.addEventListener(TimerEvent.TIMER, onTimer);
myTimer.start();
doStuff();
于 2013-03-18T21:32:04.283 回答