-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainWorker.as
38 lines (26 loc) · 920 Bytes
/
MainWorker.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.system.MessageChannel;
import flash.system.Worker;
import flash.system.WorkerDomain;
public class MainWorker extends Sprite{
public function MainWorker() {
// constructor code
trace("Worker.current.isPrimordial: " + Worker.current.isPrimordial);
if(Worker.current.isPrimordial){
var worker:Worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes);
var b2m:MessageChannel = worker.createMessageChannel(Worker.current);
var m2b:MessageChannel = Worker.current.createMessageChannel(worker);
worker.setSharedProperty("b2m", b2m);
worker.setSharedProperty("m2b", m2b);
b2m.addEventListener(Event.CHANNEL_MESSAGE, onBackToMain);
worker.start();
} else {
trace("Something is wrong!");
}
}
protected function onBackToMain(event:Event){
}
}
}