开发者

Flash AS3 Looping mc's inside of a function

开发者 https://www.devze.com 2023-03-02 16:09 出处:网络
I have a bunch of movieclips that are animated using TweenLite, (code below), but I would like to loop them 2 or 3 times continuously. I have put them inside of a function but can\'t seem to get them

I have a bunch of movieclips that are animated using TweenLite, (code below), but I would like to loop them 2 or 3 times continuously. I have put them inside of a function but can't seem to get them to loop. The starting positions for each movieclip are defined before this function - an example below also.

Any ideas where I'm going wrong? S

private var F_Apricot:Fruit_Apricot;

F_Apricot = new Fruit_Apricot();
        addChild(F_Apricot);    
        F_Apricot.x=222;
        F_Apricot.y=-189;   
        F_Apricot.scaleX=0.7;
        F_Apricot.scaleY=0.7;               
        setChildIndex(F_Apricot, 2);

function fruitLoop():void {             
            TweenLite.to(F_Passion, 1.7, {blurFilter:{blurX:8}, delay:1, x:277, y:325, scaleX:0.7, scaleY:0.7, rotation:28, ease:Cubic.easeOut});
            TweenLite.to(F_Black1, 1.7, {blurFilter:{blurX:8}, delay:1.2, x:238, y:305, scaleX:0.5, scaleY:0.5, rotation:58, ease:Cubic.easeOut});          
            TweenLite.to(F_Apricot, 1.7, {blurFilter:{blurX:8}, delay:1.5, x:303, y:305, scaleX:0.7, scaleY:0.7, rotation:47, ease:Cubic.easeOut});
            TweenLite.to(F_Raspberry, 1.7, {blurFilter:{blurX:8}, delay:1.6, x:207, y:305, scaleX:0.4, scaleY:0.4, rotation:18, ease:Cubic.easeOut});
            TweenLite.to(F_Black2, 1.7, {blurFilter:{blurX:8}, delay:1.7, x:314, y:305, scaleX:0.5, scaleY:0.5, rotation:28, ease:Cubic.easeOut});
            TweenLite.to(F_Cherries, 1.7, {blurFilter:{blurX:8}, delay:2.1, x:288, y:247, scaleX:0.6, scaleY:0.6, rotation:38, ease:Cubic.easeOut});
            TweenLite.to(F_Black3, 1.7, {blurFilter:{blurX:8}, delay:2.3, x:323, y:305, scaleX:0.4, scaleY:0.4, rotation:-8, ease:Cubic.easeOut});          
            TweenLite.to(F_Lime, 1.7, {blurFilter:{blurX:8}, delay:2.4, x:208, y:305, scaleX:0.5, scaleY:0.5, rotation:28, ease:Cubic.easeOut});            
            TweenLite.to(F_Mango, 1.7, {blurFilter:{blurX:8}, delay:2.7, x:205, y:355, scaleX:0.7, scaleY:0.7, rotation:-38, ease:Cubic.easeOut});          
            TweenLite.to(F_Black4, 1.7, {blurFilter:{blurX:8}, delay:2.9, x:188, y:305, scaleX:0.5, scaleY:0.5, rotation:-8, ease:Cubic.easeOut});
            TweenLite.to(F_Raspberry1, 1.7, {blurFilter:{blurX:8}, delay:3, x:303, y:305, scaleX:0.4, scaleY:0.4, rotation:-8, ease开发者_JS百科:Cubic.easeOut});        
        }       

        fruitLoop();


TweenLite has a parameter called onComplete which you can use to trigger your next loop.

http://www.greensock.com/as/docs/tween/_tweenlite.html


private var F_Apricot:Fruit_Apricot;

F_Apricot = new Fruit_Apricot();
  addChild(F_Apricot);    
  F_Apricot.x=222;
  F_Apricot.y=-189;   
  F_Apricot.scaleX=0.7;
  F_Apricot.scaleY=0.7;               
  setChildIndex(F_Apricot, 2);

function fruitLoop():void {     
  TweenLite.to(F_Passion, 1.7, {blurFilter:{blurX:8}, delay:1, x:277, y:325, scaleX:0.7, scaleY:0.7, rotation:28, ease:Cubic.easeOut});
  TweenLite.to(F_Black1, 1.7, {blurFilter:{blurX:8}, delay:1.2, x:238, y:305, scaleX:0.5, scaleY:0.5, rotation:58, ease:Cubic.easeOut});          
  TweenLite.to(F_Apricot, 1.7, {blurFilter:{blurX:8}, delay:1.5, x:303, y:305, scaleX:0.7, scaleY:0.7, rotation:47, ease:Cubic.easeOut});
  TweenLite.to(F_Raspberry, 1.7, {blurFilter:{blurX:8}, delay:1.6, x:207, y:305, scaleX:0.4, scaleY:0.4, rotation:18, ease:Cubic.easeOut});
  TweenLite.to(F_Black2, 1.7, {blurFilter:{blurX:8}, delay:1.7, x:314, y:305, scaleX:0.5, scaleY:0.5, rotation:28, ease:Cubic.easeOut});
  TweenLite.to(F_Cherries, 1.7, {blurFilter:{blurX:8}, delay:2.1, x:288, y:247, scaleX:0.6, scaleY:0.6, rotation:38, ease:Cubic.easeOut});
  TweenLite.to(F_Black3, 1.7, {blurFilter:{blurX:8}, delay:2.3, x:323, y:305, scaleX:0.4, scaleY:0.4, rotation:-8, ease:Cubic.easeOut});          
  TweenLite.to(F_Lime, 1.7, {blurFilter:{blurX:8}, delay:2.4, x:208, y:305, scaleX:0.5, scaleY:0.5, rotation:28, ease:Cubic.easeOut});            
  TweenLite.to(F_Mango, 1.7, {blurFilter:{blurX:8}, delay:2.7, x:205, y:355, scaleX:0.7, scaleY:0.7, rotation:-38, ease:Cubic.easeOut});          
  TweenLite.to(F_Black4, 1.7, {blurFilter:{blurX:8}, delay:2.9, x:188, y:305, scaleX:0.5, scaleY:0.5, rotation:-8, ease:Cubic.easeOut});
  TweenLite.to(F_Raspberry1, 1.7, {blurFilter:{blurX:8}, delay:3, x:303, y:305, scaleX:0.4, scaleY:0.4, rotation:-8, ease:Cubic.easeOut});  

  if(timer.currentCount>3 ){
    timer.stop()
  }       
}

    var timer:Timer = new Timer( 1000 );
    timer.addEventListener(TimerEvent.TIMER, fruitLoop )
    timer.start()


If you only need the movement to repeat a few times (versus forever) then you can setup all the transitions at once using the "delay" parameter to control what happens when. Make sure to set "overwrite" to false so that all the chained transitions happen, instead of just the last one set.

pseudocode:

TweenLite.to(obj, 500, x=0);
TweenLite.to(obj, 500, x=0, delay=500, overwrite=false);
TweenLite.to(obj, 500, x=100, delay=1000, overwrite=false);
TweenLite.to(obj, 500, x=0, delay=1500, overwrite=false);
TweenLite.to(obj, 500, x=100, delay=2000, overwrite=false);
TweenLite.to(obj, 500, x=0, delay=2500, overwrite=false);
0

精彩评论

暂无评论...
验证码 换一张
取 消