简体   繁体   中英

Flash AS3 Looping mc's inside of a function

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:Cubic.easeOut});        
        }       

        fruitLoop();
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()

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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