Created
September 10, 2012 17:13
-
-
Save silviopaganini/3692221 to your computer and use it in GitHub Desktop.
AS3 Workers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Main.as | |
function init() : void | |
{ | |
// Set the Workers Manager the swf bytes | |
Workr.bytesMain = loaderInfo.bytes; | |
// initiate the singleton | |
workr = Workr.getInstance(); | |
// create as many workers you want | |
workr.create(WorkerEnterFrame, "enterFrame"); | |
// listen for the events | |
workr.get("enterFrame").listen(workerHandler); | |
// listen for the worker start | |
workr.get("enterFrame").ready = ready; | |
// start the workers | |
workr.start(); | |
} | |
private function ready () : void | |
{ | |
workr.get("enterFrame").send("startEnterFrame"); | |
} | |
private function workerHandler(event : Event) : void | |
{ | |
trace(workr.get("enterFrame").receive()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WorkerEnterFrame.as | |
// listen for any commands | |
override protected function handleCommandMessage(command : String) : void | |
{ | |
switch(command) | |
{ | |
case "startEnterFrame": | |
addEventListener(Event.ENTER_FRAME, ef); | |
break; | |
} | |
} | |
// execute your commands and send the info back to the main application | |
private function ef(event : Event) : void | |
{ | |
counter++; | |
send(counter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment