PDA

View Full Version : how do i slow down a for() statement cycle?


MikeJump
02-02-2005, 12:16 AM
for(var i:Number = 0; i <= 7; i++){
eval(eval("b"+i)).onRollOver = function():Void{
for(var ii:Number = 0; ii<=100; ii++){
something to slow this down.
this._alpha = ii;
}
}
};


Red area I would like to slow the cycle way down..
thanks
Mike

huxflux
02-02-2005, 12:48 AM
it's not possilbe but setInterval and a conditional statement would do the job.
so it would be something like:
setInterval(function(){if(condition){your statement here}},10)
this function is called every 10 milliseconds

MikeJump
02-02-2005, 01:03 AM
c'mon there has got to be a way to do this... (:

(: well i would like to keep this code simple and slow the for() cycle down quite a bit.. there has got to be a way.
are you sure?


thanks (:
Mike

tdoublea
02-02-2005, 01:15 AM
hello mikeJump.

do you actually see a transition using the for loop? my machine runs through it first then renders it. (which i think is supposed to happen)

setInterval is a good idea, or set an onEnterFrame in the first for loop that counts up to 100 and delete it once it's there.

i would also recommend checking into the Fade class that's within the mx.transition package.
these sites don't deal directly with Fade, but give you an idea of how to use the transitions:
http://www.macromedia.com/devnet/mx/flash/articles/tweening.html
http://www.actionscript.org/tutorials/advanced/Tween-Easing_Classes_Documented/index.shtml

using this, you can cut out the nested for loop from your code and set the transition in another function.

hope it helps
-t

shinew7911
02-02-2005, 07:10 AM
I don't think the for() statement is meant to be slowed down, which is why there is setInterval() & onEnterFrame... though you can use a slower machine...:D

yea, I would use setInterval() or onEnterFrame.

xxlm
02-02-2005, 12:03 PM
For loop can't be slowed.
For statement doing first all the loop then affect the object properties.
So even if you find something that could slow the for loop (what I don't think you'll find) you'll never see the transition.

A good component every flash developper need to have is this one:
http://laco.wz.cz/
See and enjoy.

back to your problem to execute an action every X second, use setInterval and a function linked to it.

C ya

shinew7911
02-02-2005, 06:24 PM
wow, that's amazing, is it written in AS? how can I take a look at the code? or is it not downloadable...?

UncleML
02-02-2005, 07:42 PM
Try this out. I assume all your 7 mcs are named with prefix "mc_a" followed by digit from 0 to 7. You can't make them all completely invisible by setting to alpha=0 as you are not able to rollover them. So, I just give you example to set them all to alpha 25%. When you roll over particular movieclip, the system will perform a loop to increment that particular movieclip's alpha by 1 (from 25) until it reaches 100 (transition in progress), the loop for that movieclip will be terminated. This code must be placed in the main timeline.


for(var i:Number = 0; i <= 7; i++){
_root["mc_a"+i]._alpha=25;
_root["mc_a"+i].onRollOver = function():Void{
this.onEnterFrame=function():Void{
this._alpha++;
if (this._alpha>=100) this.onEnterFrame=null;
};
}
};

UncleML
02-02-2005, 07:46 PM
for(var i:Number = 0; i <= 7; i++){
_root["mc_a"+i]._alpha=25;
_root["mc_a"+i].onRollOver = function():Void{
this.onEnterFrame=function():Void{
this._alpha++;
if (this._alpha>=100) this.onEnterFrame=null;
};
}
};

MikeJump
02-02-2005, 08:01 PM
b0 = "mcMenu.mcAbout";
b1 = "mcMenu.mcMusic";
b2 = "mcMenu.mcPhoto";
b3 = "mcMenu.mcVideo";
b4 = "mcMenu.mcNews";
b5 = "mcMenu.mcJournal";
b6 = "mcMenu.mcLinks";
b7 = "mcMenu.mcEmail";

//This creates Eventhandlers for each of the paths.
for(var i:Number = 0; i < 8; i++){
_root["b"+i].onRollOver = function():Void{
this._alpha = 0;
}
};

//this function constantly adds 1 to the alpha value of all.
fadeUp = function():Void{
for(var i:Number = 0; i<8; i++){
_root["b"+i]._alpha++
trace(eval(eval("b"+i))._alpha)

}
};




the root thing doesnt work... so i added the whole code for you to see.

also. ill read about onEnterFrame. because i never used it
thanks
Mike

UncleML
02-02-2005, 08:22 PM
Try this. You may place a trace on the onEnterFrame to check whether the system will loop upon completion of transition. Are you actually wanted to change the alpha to *zero upon rollover and then growing gradually to 100. So, the below may help. I like to use array (which I defined using flash mx code, you might change the array to Flash MX 2004).

arrMC=new Array();
arrMC[0]="mcMenu.mcAbout";
arrMC[1]="mcMenu.mcMusic";
arrMC[2]="mcMenu.mcPhoto";
arrMC[3]="mcMenu.mcVideo";
arrMC[4]="mcMenu.mcNews";
arrMC[5]="mcMenu.mcJournal";
arrMC[6]="mcMenu.mcLinks";
arrMC[7]="mcMenu.mcEmail";

for(var i:Number = 0; i < arrMC.length; i++){
_root[arrMC[i]].onRollOver = function():Void{
this._alpha=25;
this.onEnterFrame=function():Void{
this._alpha++;
if (this._alpha>=100) this.onEnterFrame=null;
};
}
};

UncleML
02-02-2005, 08:24 PM
arrMC=new Array();
arrMC[0]="mcMenu.mcAbout";
arrMC[1]="mcMenu.mcMusic";
arrMC[2]="mcMenu.mcPhoto";
arrMC[3]="mcMenu.mcVideo";
arrMC[4]="mcMenu.mcNews";
arrMC[5]="mcMenu.mcJournal";
arrMC[6]="mcMenu.mcLinks";
arrMC[7]="mcMenu.mcEmail";

for(var i:Number = 0; i < arrMC.length; i++){
_root[arrMC[i]].onRollOver = function():Void{
this._alpha=0;
this.onEnterFrame=function():Void{
this._alpha++;
if (this._alpha>=100) this.onEnterFrame=null;
};
}
};

xxlm
02-02-2005, 09:30 PM
shinew7911> component for ease, fade, slide, alpha, ... can be found here:
http://laco.wz.cz/tween/

MikeJump> UncleML should work, but I will advise you to use the component I refer above. It will be cleaner and easier to update.

C ya