A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: help with for () command

  1. #1
    Member
    Join Date
    Dec 2003
    Posts
    45

    help with for () command

    I have 7 movieclips that I called command1, command2, command3, ...

    for each of them, I want to set their alpha value to 0

    so, I use the command for()

    for(i=1; i<8; i++){
    ???._alpha = 0;

    but I don't know how to write the statement, I need help please

    thanks

    MaX_BoY

  2. #2
    Senior Member
    Join Date
    Nov 2003
    Posts
    524
    Hi MaX_BoY,

    if you want to just set there alpha to 0 then you can just use
    command1._alpha=0;
    command2._alpha=0;

    If you want them to fade from alpha 100 to alpha 0 then you would not use a for loop as it will happen so fast that it will just seem like from 100 to 0 with nothing between. So if you want a fade you have to do it over time and for this you need a loop based on time.
    As you have a number of Movie Clips I would just add a fadeUp and fadeDown to the Movie clip object. This means that all your Movie Clips can then fade up or down if you want them to.

    Here is how.I have put some comments for you so you know a bit of what is going on.
    Code:
    //give all Movie Clips a special timer variable
    MovieClip.prototype.fadeInterval=undefined;
    //next the speed of the fade, how often the fadeIncr is added to 
    //the movie clip _alpha in milliseconds (1000 milliseconds per sec.)
    MovieClip.prototype.fadeSpeed=50;
    //next the increment that will be added to the Movie Clip _alpha
    MovieClip.prototype.fadeIncr=2;
    
    //and here is the fade down function
    MovieClip.prototype.fadeDown=function(){
          clearInterval(this.fadeInterval);
    	  this.fadeInterval=setInterval(fader,this.fadeSpeed,this);
    	  function fader(mc){
    		  if(mc._alpha>0){mc._alpha-=mc.fadeIncr;}
    		  else{clearInterval(mc.fadeInterval);
    		  }
    	  }
    }
    
    //and here is the fade up function
    MovieClip.prototype.fadeUp=function(){
    	  clearInterval(this.fadeInterval);
    	  this.fadeInterval=setInterval(fader,this.fadeSpeed,this);
    	  function fader(mc){
    		  if(mc._alpha<100){mc._alpha+=mc.fadeIncr;}
    		  else{clearInterval(mc.fadeInterval);
    		  }
    	  }
    }
    then You can make ANY Movie clip fade up or down by just calling the function. ie:
    command1.fadeUp();
    command2.fadeDown();
    command3.fadeUp();
    someOtherMoviClip.fadeUp();

    Have fun ... I hope it helps and gives you lots of ideas of what you can do like this.
    Shipstern

  3. #3
    Member
    Join Date
    Dec 2003
    Posts
    45
    thank you

  4. #4
    Senior Member
    Join Date
    Nov 2003
    Posts
    524
    Hi MaX_BoY,
    I thought I should answer you question about the for() ...

    If you did do it with a for() loop

    for(i=1; i<8; i++){
    this["command"+i]._alpha = 0;
    }

    You may want to use _root["command"+i]._alpha=0; it depends where your command clips are located.

    Shipstern

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