A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Simplify code

  1. #1
    Member
    Join Date
    Sep 2009
    Posts
    66

    Simplify code

    Hello,

    how can i simplify this code:

    PHP Code:
    stop();

    import com.greensock.*;
    import com.greensock.easing.*;
    import flash.events.MouseEvent;

    var 
    timeline:TimelineMax= new TimelineMax({paused:true});
    var 
    timeline1:TimelineMax= new TimelineMax({paused:true});
    var 
    timeline2:TimelineMax= new TimelineMax({paused:true});

    timeline.append(TweenMax.to(alfa,3, {y:150alpha:1ease:Elastic.easeInOut}));
    timeline1.append(TweenMax.to(beta,3, {y:200alpha:1ease:Elastic.easeInOut}));
    timeline2.append(TweenMax.to(teta,3, {y:200alpha:1ease:Elastic.easeInOut}));

    boton.addEventListener(MouseEvent.CLICKprueba);

    function 
    prueba(e:MouseEvent):void{
        
    timeline2.reverse();
        
    timeline1.reverse();
        
    timeline.play();
    }

    boton1.addEventListener(MouseEvent.CLICKprueba1);

    function 
    prueba1(e:MouseEvent):void{
        
    timeline.reverse();
        
    timeline2.reverse();
        
    timeline1.play();
    }

    boton2.addEventListener(MouseEvent.CLICKprueba2);

    function 
    prueba2(e:MouseEvent):void{
        
    timeline.reverse();
        
    timeline1.reverse();
        
    timeline2.play();

    I think, for loop can be used but i don't know how

    Thanks for your help

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    stop();
    
    import com.greensock.*;
    import com.greensock.easing.*;
    import flash.events.MouseEvent;
    
    var currBtn:DisplayObject;
    var btnArray:Array = [[boton, alfa, 150], [boton1, beta, 200], [boton2, teta, 200], ];
    btnArray.map(makeIt);
    
    function makeIt(element:*, index:int, arr:Array):void {
    	var timeline:TimelineMax=new TimelineMax({paused:true});
    	timeline.append(TweenMax.to(element[1], 3, {y:element[2], alpha:1, ease:Elastic.easeInOut}));
    	element.push(timeline);
    	element[0].addEventListener(MouseEvent.CLICK, setCurrBtn);
    }
    
    function setCurrBtn(e:MouseEvent):void {
    	currBtn=e.currentTarget as DisplayObject;
    	btnArray.map(doTimelines);
    }
    
    function doTimelines(element:*, index:int, arr:Array):void {
    	if (element[0]==currBtn) {
    		element[3].play();
    	} else {
    		element[3].reverse();
    	}
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center