This content has been marked as final. Show 7 replies
Flash renders it's frames in 'Race Track' fashion, that is, for every frame, it executes ALL of your AS, then updates its vectors, THEN draws the new frame. So, if you take 60 seconds to execute some code, flash will wait until you're done to render any new frames. Your interval function will be called, but you'll never see it, because flash is still waiting on your other AS before it will render any new frames.
If you want to update the user about the progress of this large calculation, you're going to have to use a setInterval or onEnterFrame to break up the calculation itself. For example, you could use the generic setup below. You'd undoubtedly have to make some adjustments to break up the calculations, but that's really your only option other than popping up a modal graphic to tell the user to hang tight.
The simplicity of your solution brings tears to my eyes. This is something I'd been grappling with in many circumstances for many a long time.
I didn't want to have to add new frames to handle this and your code effectively "simulates" new frames by breaking up calculations into what could be "frameable" computations, but instead handling it at the actionscript level.
Between you and me, I like your solution a whole lot better.
Thank you, thank you, thank you. I owe you one. If you're ever in Boston, I'll buy you a beer.
Hi again Tony, others,
So, this strategy works perfectly in a typical Flash file.
As I attempt to integrate it into an external class within a Slide-based Flash application, I run into trouble. I have a class called oil.Simulator.Simulation which extends MovieClip. The function that "Advances" the simulation is called "Advance". It simply sets up a function pointer for onEnterFrame to run. Interestingly, the function runs once, and once only. Here is the code - I've given you the whole class but focus in on the Advance() and _Advance() functions.
Many thanks for any additional pointers you might have.
Interestingly, if I add the line:
onEnterFrame = this._Advance();
at the end of each case in the _Advance() function, I can make through it. Who or what is assigning onEnterFrame to null while I'm not looking?
I am definitely not the world's foremost authority on classes in AS, but if I had to take a guess, it would be that when you set the onEnterFrame in Advance(), it gets treated as a local object and deleted after the function executes. To solve this problem, I THINK you could just set this.onEnterFrame instead. And if that works, you'll have to change your last line of _Advance as well. Hope that helps... ;)
Thanks again Tony. Your suggestion didn't work, but interestingly, the same concept using setInterval() seems to work fine.