It's not that the changes are happening too fast to see. It's that nothing is getting drawn to the screen until the entire sort() method has finished.
The Flash Player does delayed frame rendering. Drawing commands don't get rasterized into pixels while your ActionScript method is executing. And you can't create multiple threads in ActionScript. You need to break up your sorting routine so that it executes one (or a few) swaps at a time -- either frame-by-frame by using callLater(), or at a specified interval by using Time. The player can then do swap some values render to screen swap some values render to screen ... Gordon Smith Adobe Flex SDK Team ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Nicholas Sent: Monday, May 12, 2008 10:07 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Delay recursive function I've looked for other threads on this, but haven't found anything that has really helped me yet. I've made a sorting function that dispatches an event every time it swaps values in an array. The eventlistener calls a function that updates a display to show visually how the array has changed. The problem is that when I call the sort function, there's only a slight hesitation and then the display changes to the end result. I'm guessing that the changes are happening too fast for the user to see. In a Java environment, I would just Thread.sleep during the sort function to slow it down, but I can't do that in AS3. Does anyone have any ideas? I've looked all over, but it's possible I'm just not properly using the solutions I've found. In case it helps, here's the basic layout of the class: class Sort { function partition(a:Array, l:int, r:int):int { // look around // swap values dispatchEvent(SortEvent.UPDATE); // SortEvent is a custom event // would like to pause this function here return value; } function sort(a:Array, l:int, r:int) { if (l >= r) return; var i:int = partition(a,l,r); sort(a, l, i-1); sort(a, i+1, r); } }