as3 custom functions
i'm new to AS3. how do i go about executing a custom function n number of times and then executing another function n number of times repeatedly?
eg.
function firstOne():void { }
function secondOne():void { }
i need firstOne() executed say 3 times and then secondOne() 3 times and then firstOne 3 times again and so on. i'm trying to move a movieclip 3 times to the left and then 3 times to the right continuously.
t开发者_Go百科hanks
i think what you have a problem with is that you are needing a time lapse if you are moving a movieclip. corrodeds answer is correct, but it will operate firstOne three times in the same frame, if you have a tween etc in there then they will just overwrite everything.
i would have a counter and function holder with a looping event, either add it to a Timer event, ENTER_FRAME event or as the onComplete event to a tween.
private var endFunc:Function = firstOne;
private var count:int = 0;
private function step(ev:Event) //CATCH ANY EVENT ETC IN HERE
{
int ++;
if(int>3){
int = 0;
if(endFunc == firstOne){ endFunc = sencondOne };
else { endFunc = firstOne };
}
endFunc();
}
why not make a third function that has an input of how many times you want to iterate?
function thirdFunction(times_iterated:Number):void {
for(i=0; i<times_iterated; i++) {
firstOne();
}
}
then so for the second function
精彩评论