views:

2728

answers:

4

Hello!

I was wondering if there are any code or class libraries out there on how to implement multithreading or "green threading" in ActionScript.

As you've might seen, Scott Peterson is developing some kind of toolset, but I haven't found any more info on this other than his performance on the Adobe MAX Chicago event.

Regards Niclas

+1  A: 

There's no built-in way to do green threading in ActionScript. You have to write code to handle it.

Make a function that performs one iteration of whatever operation you want to do. It should return true or false depending on if its job is done or not. Now, you have to compute the time interval left to the next screen update on the ENTER_FRAME event. This can be done using flash.utils.getTimer.

start = getTimer();
//thread is a ui component added to system manager that is redrawn each frame
var fr:Number = Math.floor(1000 / thread.systemManager.stage.frameRate);
due = start + fr;

Keep on executing your function while checking the function's return value each time and checking if due time has been crossed by comparing getTimer() with due.

This has been implemented into a usable class by Alex Harui in the blog entry - Threads in ActionScript

anirudhsasikumar
A: 

I'm a graphics guy, not a programmer, so I'm not sure this will help you. BUT!

I make all my GUIs multi-frame "movies" and write each gui thread on a different frame. Make sure that you only have 1-3 threads, and set your FPS to 30 or 60.

This is useful for little projects because its bug-resistant and implementation is done for you.

+2  A: 

Here's a Green Threading lib from Drew Cummins:

http://blog.generalrelativity.org/?p=29

RickDT
+1  A: 

It's an old article, but quasimondo's method of launching multiple swfs and then sharing the data over a LocalConnection may also be of interest. They were saying that the back and forth of using the LocalConnection may eat up a few cycles, but if the iterations being processed are complex enough it shouldn't be too much of a problem.

Assembler