This content has been marked as final. Show 10 replies
no multi-threading. code executes sequentially (except of a handful of asynchronous functions, like load functions).
hi kglad! i'm always honored when you respond.
Flash definitely has at least has some quasi-multithreading going on...maybe it's not true multithreading (as in it capitalizes on a quad-core cpu) but it does exhibit some semblance of multithreading behavior.
for instance, suppose I spawn ten movie clips on the first frame of my flash project, each of which contacts a different webserver and handles the results with an onLoad event. While the execution of the outgoing requests might be predictable (or is it?), somebody somewhere is multithreading to handle the synchronization required to get all those responses back into my flash movie. I have no guarantees about the sequence in which the onLoad events will be executed and I'm not even sure that one particular onLoad event won't be interrupted to start another onLoad event. see what i mean? What level of granularity can I expect from Flash code execution? Are there any hard-and-fast rules about when code is interrupted and when it's not?
I was hoping to learn a bit more about how Flash simultes this concurrent execution.
like i said, load functions are asynchronous. anything being retrieved outside the swf is going to be available asynchronously. everything else is synchronous.
in particular, load requests are synchronous. the onLoad functions are going to execute asynchronously.
a.s. code is not interrupted (except when it exceeds the time limit setting or flash detects 256 indentical loops.
THANKS for the answer!
How do you *know* this stuff kglad? Is there anywhere this is documented in more detail? I want to make sure my project doesn't have problems and I think I need a little more detail.
i don't know if it's documented. it probably is, but i don't recall ever reading about it.
i've learned about most a.s. code being synchronous by testing in flash. i've learned about load results being asynchronous by thinking they were synchronous (actually, i wasn't thinking at all) and having problems using or referencing assets that weren't available.
So I've been trying to construct a test script to hopefully understand this better but I'm having a bit of a problem. I made a loop to create 10 loadvars objects loading each from a different website. I was hoping to make the 10 onLoad functions for each loadVars identify itself when it runs but all 10 loadVars objects are pointing to the exact same memory location rather than the value of i when they were created so I cannot distinguish the different loadVars objects...my code is attached.
EDIT: reformatted code to fix tab/spaces issue
OK i got it fixed. I think this code pretty clearly illustrates just how sequential flash code execution is. Not a single onLoad event runs until all of the loadVars objects have been created even though the main loop spends A LOT of time doing nothing. I'm pretty sure most of the loadvars objects are loaded by the time the main loop completes and Flash still makes them wait til the main loop finishes.
I'm still wondering if there is any chance for race conditions or deadlock or any other weirdness in my code but I have a much better idea of how things work.
for-loops execute from beginning to end and cannot be interrupted, once they start, by anything else that occurs in a swf.
That's really useful info! I'm guessing that a function won't be interrupted either. Adobe should have docs on this somewhere. If they don't, well that's just *shameful*.
a function's block of code is no different than any other lines of code: it executes synchronously, except for load functions.