Multithreading or green threading in actionscript?

删除回忆录丶 提交于 2019-12-01 08:25:06

Here's a Green Threading lib from Drew Cummins:

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

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!