Reputation: 283
I have an application made in AIR that uses Worker object. Now, I need close my application through it, but I don't know how to do this...
Here's what I've tried:
NativeApplication.nativeApplication.exit();
exits Worker, not ApplicationSystem.exit(0);
not work in AIR, only FP Debuggerfscommand('quit');
not work in AIR, only FPNativeApplication.nativeApplication.openedWindows[i].close();
in for, openedWindows.length returns '0'WorkerDomain.current.listWorkers[i].terminate();
in for, terminate() don't work when 'isPrimordial' is true and the current Worker is a background Worker.How can I exit my application through a background Worker?
Example code:
package {
import flash.desktop.NativeApplication;
import flash.system.fscommand;
import flash.system.System;
import flash.system.Worker;
import flash.system.WorkerDomain;
public class Main extends Sprite {
private var _worker:Worker;
public function Main() {
if(Worker.current.isPrimordial) {
_worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes, true);
_worker.start();
trace("create worker");
}
else {
trace("Worker started, lets close app!");
//NativeApplication.nativeApplication.exit();
//System.exit(0);
//fscommand("quit");
//NativeApplication.nativeApplication.openedWindows.length;
//WorkerDomain.current.listWorkers[0].terminate();
}
}
}
}
Upvotes: 1
Views: 76
Reputation: 14406
Though I haven't done this before, perhaps this would be a good way to implement this:
When you create your worker, listen for the TERMIANTED state change event, which will be dispatched when you terminate the worker (I"m not sure if doing nativeapplication.exit triggers this event, or if you have to explicitly call the terminate()
method):
_worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes, true);
_worker.addEventListener(WorkerState.TERMINATED, workerFinished, false, 0, true);
_worker.start();
Then, in that handler, exit the application:
private function workerFinished(e:Event):void {
NativeApplication.nativeApplication.exit();
}
Upvotes: 1