PDA

View Full Version : Show frame before function is complete?


simulate
07-05-2006, 06:46 PM
Hello,

I have a two frame movie. On the first frame is a button with the code:

_parent.gotoAndStop(2);

On the second frame, I want to show iterations of a calculation as the calculation is running. Here's the code for frame 2:

stop();
calculate();
function calculate() {
for (var f = 1; f <= 30000; f++) {
resultsField.value = "Completed " + f + " of 30000 iterations.";
}
}

The problem I am having is that frame 2 doesn't show until the calculate() function is completed. So, instead of seeing the resultsField advance through the 30000 iterations, I just wait on frame 1 until the function has completed and then I see the final 30000th iteration on frame 2.

Is there a way to show the iterations on frame 2 as the iterations are taking place?

Attached is the .fla with the example.

Thanks for your help!

simulate
07-06-2006, 05:22 PM
I found the solution. The solution is to use onEnterFrame within the calculate() function:

function calculate() {
var f=1;
this.onEnterFrame=function() {
if(f<=3000) {
f++;
resultsField.value = "Completed " + f + " of 3000 iterations.";
} else {
this.onEnterFrame=null;
}
}
}