Need short code fix

Im tryind to make flash wait a certain random amount of time at the end of a mc, here’s what i wrote:


i = math.Random()*20+10;
while (true) {
	if (i >= 1000) {
		break;
	}
	i++;
}

i dont know what i’ve done wrong, but im not an AS god so any help will be welcomed (and if there is a nother way with time in seconds i would appreciate, although i havent found anything)

look up getTimer() thats what you are looking for…

i did that previously but i really dont know how the timer works…
is it in milliseconds ?

haha… I remember doing something like that back in the days of BASIC…

I tried to do something like that recently, but you can’t do it in flash… why? because flash will do that loop in less time than it takes to switch from frame to frame…

you can do something like this with an empty movie clip


onClipEvent(load){
     limit = math.Random()*20+10;
     secondspassed = 0
     var temp = time.getSeconds();
}

// basically what you're doing is checking if the seconds change... 
// if they do, you increase a counter, and then when that counter 
// is equal to whatever number of seconds the computer 
// randomly chose, it will go to whatever frame you want...

onClipEvent(EnterFrame){
     var second = time.getSeconds();

     if (second != temp){
          secondspassed++
          temp = second
          }

     if (secondspassed > limit){
          gotoAndPlay(3)
          }
}

you can have that on frame 1, and then on frame 2 you’ll have



gotoAndPlay(1)

I know there’s a way to set an interval in flash, but I’m not sure. But this is the way I’d do it if I wanted to use a loop… Also, I dont have flash on this computer, so I cant check that it worked, but i think it should…

thnx very much, i found out too that flash loops zillions of time before the condition is reached… i found another method…
i just added 40 blank frames at the end of my movie and an action just goes randomly to one… and plays. Sort of escaped the problem.

thnx for your help

-mlk:elderly:

hmm… that was creative… I hadnt thought of that…

you’re welcome