{"id":13744183,"url":"https://github.com/myflashlab/easyAS-Worker","last_synced_at":"2025-05-09T02:32:50.954Z","repository":{"id":146413480,"uuid":"50616749","full_name":"myflashlab/easyAS-Worker","owner":"myflashlab","description":"Run AS worker in your AdobeAir projects without having to deal with complicated flash.system.Worker class","archived":false,"fork":false,"pushed_at":"2017-06-19T16:18:10.000Z","size":257,"stargazers_count":47,"open_issues_count":5,"forks_count":12,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-15T15:42:18.037Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"ActionScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/myflashlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-01-28T21:57:02.000Z","updated_at":"2024-09-13T16:01:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5b8c4d3-1244-48b6-8ffb-6bb2b34ba7e0","html_url":"https://github.com/myflashlab/easyAS-Worker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myflashlab%2FeasyAS-Worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myflashlab%2FeasyAS-Worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myflashlab%2FeasyAS-Worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myflashlab%2FeasyAS-Worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/myflashlab","download_url":"https://codeload.github.com/myflashlab/easyAS-Worker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253177858,"owners_count":21866409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T05:01:04.689Z","updated_at":"2025-05-09T02:32:50.250Z","avatar_url":"https://github.com/myflashlab.png","language":"ActionScript","funding_links":[],"categories":["Native Extension","Utilities"],"sub_categories":["System ANE"],"readme":"# Easy AS Workers for Adobe Air AS3 projects\nThis AS3 library lets you run AS workers in your AdobeAir projects, desktop, browser, Android and iOS without you having to deal with complicated classic ```flash.system.Worker;``` class! [**Check here for more setup details**](http://www.myflashlabs.com/developer-friendly-as-worker-api/)\n\n# USAGE\nFirst create your worker class where you need to run your heavy code algurithm. take ```Worker1``` class as an example.\n```actionscript\npackage workers\n{\n\timport com.myflashlabs.utils.worker.WorkerBase;\n\t\n\t/**\n\t * ...\n\t * @author MyFlashLab Team - 1/28/2016 11:00 PM\n\t */\n\tpublic class Worker1 extends WorkerBase\n\t{\n\t\t\n\t\tpublic function Worker1()\n\t\t{\n\t\t\n\t\t}\n\t\t\n\t\t// these methods must be public because they are called from the main thread.\n\t\tpublic function forLoop($myParam:int):void\n\t\t{\n\t\t\tvar thisCommand:Function = arguments.callee;\n\t\t\t\n\t\t\tfor (var i:int = 0; i \u003c $myParam; i++)\n\t\t\t{\n\t\t\t\t// call this method to send progress to your delegate\n\t\t\t\tsendProgress(thisCommand, i);\n\t\t\t}\n\t\t\t\n\t\t\t// call this method as the final message from the worker. When this is called, you cannot send anymore \"sendProgress\"\n\t\t\tsendResult(thisCommand, $myParam);\n\t\t}\n\t\n\t}\n}\n```\n\nThen, in your main project, all you need to do is to initialize ```com.myflashlabs.utils.worker.WorkerManager``` and run your worker whenever you wish.\n```actionscript\npackage\n{\n\timport flash.display.Sprite;\n\timport flash.events.Event;\n\timport flash.system.WorkerState;\n\timport flash.text.TextField;\n\timport flash.text.TextFieldAutoSize;\n\timport flash.text.TextFormat;\n\t\n\timport workers.Worker1;\n\t\n\t// WorkerManager which will be taking care of all complicated stuff about AS Workers for you\n\timport com.myflashlabs.utils.worker.WorkerManager;\n\t\n\t/**\n\t * ...\n\t * @author Hadi Tavakoli - 1/29/2016 1:17 AM\n\t */\n\tpublic class Main extends Sprite\n\t{\n\t\tprivate var _myWorker:WorkerManager;\n\t\tprivate var _txt:TextField;\n\t\t\n\t\tpublic function Main()\n\t\t{\n\t\t\t_txt = new TextField();\n\t\t\t_txt.autoSize = TextFieldAutoSize.LEFT;\n\t\t\t_txt.defaultTextFormat = new TextFormat(null, 40);\n\t\t\t_txt.x = _txt.y = 50;\n\t\t\tthis.addChild(_txt);\n\t\t\t\n\t\t\t// init the Manager and pass the class you want to use as your Worker\n\t\t\t_myWorker = new WorkerManager(workers.Worker1, loaderInfo.bytes, this);\n\t\t\t\n\t\t\t// listen to your worker state changes\n\t\t\t_myWorker.addEventListener(Event.WORKER_STATE, onWorkerState);\n\t\t\t\n\t\t\t// fire up the Worker\n\t\t\t_myWorker.start();\n\t\t}\n\t\t\n\t\tprivate function onWorkerState(e:Event):void\n\t\t{\n\t\t\ttrace(\"worker state = \" + _myWorker.state)\n\t\t\t\n\t\t\t// if the worker state is 'running', you can start communicating\n\t\t\tif (_myWorker.state == WorkerState.RUNNING)\n\t\t\t{\n\t\t\t\t// create your own commands in your worker class, Worker1, i.e \"forLoop\" in this sample and pass in as many parameters as you wish\n\t\t\t\t_myWorker.command(\"forLoop\", onProgress, onResult, 10000);\n\t\t\t}\n\t\t}\n\t\t\n\t\t/**\n\t\t * this function can have as many parameters as you wish. \n\t\t * this is just a contract between the worker class and this delegate.\n\t\t * What you need to notice though, is that it must return void.\n\t\t */\n\t\tprivate function onProgress($progress:Number):void\n\t\t{\n\t\t\t_txt.text = \"$progress = \" + $progress;\n\t\t}\n\t\t\n\t\t/**\n\t\t * this function can have as many parameters as you wish. \n\t\t * this is just a contract between the worker class and this delegate.\n\t\t * What you need to notice though, is that it must return void.\n\t\t */\n\t\tprivate function onResult($result:Number):void\n\t\t{\n\t\t\t_txt.text = \"$result = \" + $result;\n\t\t\t\n\t\t\t// terminate the worker when you're done with it.\n\t\t\t_myWorker.terminate();\n\t\t}\n\t}\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyflashlab%2FeasyAS-Worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmyflashlab%2FeasyAS-Worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyflashlab%2FeasyAS-Worker/lists"}