使用Worker Class在动作脚本中进行多线程处理

时间:2015-04-17 13:10:10

标签: actionscript-3 flex

我的主线程被暂停,我是动作脚本的新手。 可能是造成这种错误的原因。

 Main Thread (Suspended: VerifyError: Error #1014: Class flash.system::Worker   could not be found.)    

enter image description here

2 个答案:

答案 0 :(得分:0)

此错误与工作进程未初始化有关。如果您正在使用它,请尝试将Flash播放器更新到最新版本和Flash构建器。

请查看此链接了解更多信息 https://forums.adobe.com/thread/1037293

答案 1 :(得分:0)

如果你有问题要使用或实施Workers我做了一个lib来帮助这个,如果你想要你可以贡献..只需登记GitHub ASWorker Link

实施就像这样

package
{
    import com.tavernari.asworker.ASWorker;
    import com.tavernari.asworker.notification.NotificationCenter;
    import com.tavernari.asworker.notification.NotificationCenterEvent;

    import flash.display.Sprite;

    public class ASWorkerDemo extends Sprite
    {
        private var asWorker:ASWorker;

        //BOTH AREA

        public function ASWorkerDemo()
        {
            //important know, all class start here will be replicated in all works.
            asWorker = new ASWorker(this.stage, uiWorkerStartedHandler, backWorkerStartedHandler);  
        }

        //BOTH AREA END

        //UI AREA START
        private function uiWorkerStartedHandler():void{
            //implement all class or calls for your UI

            NotificationCenter.addEventListener("FROM_BACK_EVENT_MESSAGE", onFromBackEventMessageHandler );

        }

        private function onFromBackEventMessageHandler(e:NotificationCenterEvent):void
        {
            trace(e.data);

            if(e.data == "completed job"){
                NotificationCenter.dispatchEventBetweenWorkers( new NotificationCenterEvent("NEXT_MESSAGE") );
            }
        }

        //UI AREA END

        //BACK AREA START

        private function backWorkerStartedHandler():void{
            //implement all class or calls for your BACK operations 
            NotificationCenter.addEventListener("NEXT_MESSAGE", uiCallForNextMessageHandler );
        }

        private function uiCallForNextMessageHandler():void
        {
            for(var i:int = 0; i < 15; ++i){
                NotificationCenter.dispatchEventBetweenWorkers( new NotificationCenterEvent("FROM_BACK_EVENT_MESSAGE", false, i) );
            }

            NotificationCenter.dispatchEventBetweenWorkers( new NotificationCenterEvent("FROM_BACK_EVENT_MESSAGE", false, "completed job") );
        }

        // BACK AREA END
    }
}

祝福工人好运