I wanna make this code better

  • bmcc81
  • Newbie
  • Newbie
  • User avatar
  • Posts: 9

Post 3+ Months Ago

Hi,

I just wrote this and it seems a little long. As if you could make it shorter. Anywayif anyone can help shorten this code, I'd like to learn.

Code: [ Select ]
var i:Number = 1;

function DoRandom() {
var target_x = home_x - content_mc["section_"+i]._x;
content_mc.slideTo( target_x, "0", 2 );
i++;
if(i==6) clearInterval(intervalID);
if(i==6) var target_x = home_x-content_mc.section_0._x;
    content_mc.slideTo(target_x,"0",2);
    if(i==1) var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 70, 1, true);
    if(i==2) var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 50, 1, true);
    if(i==2) var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 70, 1, true);
    if(i==3) var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 50, 1, true);
    if(i==3) var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 70, 1, true);
    if(i==4) var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 70, 1, true);
    if(i==4) var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 50, 1, true);
    if(i==5) var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 70, 1, true);
    if(i==5) var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 50, 1, true);
    if(i==6) var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 50, 1, true);
    if(i==6) var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 70, 1, true);


var intervalID = setInterval(DoRandom, 4000);
  1. var i:Number = 1;
  2. function DoRandom() {
  3. var target_x = home_x - content_mc["section_"+i]._x;
  4. content_mc.slideTo( target_x, "0", 2 );
  5. i++;
  6. if(i==6) clearInterval(intervalID);
  7. if(i==6) var target_x = home_x-content_mc.section_0._x;
  8.     content_mc.slideTo(target_x,"0",2);
  9.     if(i==1) var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 70, 1, true);
  10.     if(i==2) var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 50, 1, true);
  11.     if(i==2) var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 70, 1, true);
  12.     if(i==3) var alphaT:Tween = new Tween(b_1, "_alpha", Regular.easeOut, 50, 50, 1, true);
  13.     if(i==3) var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 70, 1, true);
  14.     if(i==4) var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 70, 1, true);
  15.     if(i==4) var alphaT:Tween = new Tween(b_2, "_alpha", Regular.easeOut, 50, 50, 1, true);
  16.     if(i==5) var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 70, 1, true);
  17.     if(i==5) var alphaT:Tween = new Tween(b_3, "_alpha", Regular.easeOut, 50, 50, 1, true);
  18.     if(i==6) var alphaT:Tween = new Tween(b_4, "_alpha", Regular.easeOut, 50, 50, 1, true);
  19.     if(i==6) var alphaT:Tween = new Tween(b_0, "_alpha", Regular.easeOut, 50, 70, 1, true);
  20. var intervalID = setInterval(DoRandom, 4000);



Thanks,
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

well you could use a case statement. Thats a lot easier than a your long list of if's. You could also write the alphaT line once and use variables to fill in the arguements. IE
Code: [ Select ]
var targ="b_4";
etc

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 14 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.