package zip {
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.EventDispatcher;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.system.Worker;
import flash.system.WorkerDomain;
import flash.system.WorkerState;
import flash.utils.ByteArray;
import deng.fzip.FZip;
import deng.fzip.FZipFile;
import flash.display.Loader;
import flash.display.LoaderInfo;

public class ZIPResourceLoader extends EventDispatcher {
public var resourcesURL:String = "https://redagereborn.ru/resources.zip";
public var versionURL:String = "https://redagereborn.ru/version.txt";
public var localFilePath:String = File.applicationStorageDirectory.nativePath + File.separator + "resources.zip";
public var versionFile:File = new File(File.applicationStorageDirectory.nativePath + File.separator + "version.txt");
public var zipLoader:URLLoader = new URLLoader();
private var progressBar:ProgressBar;
private var worker:Worker;
private var workerIsRunning:Boolean = false;

public function ZIPResourceLoader(progressBar:ProgressBar) {
loadWorkerSWF();
this.progressBar = progressBar;
zipLoader.dataFormat = URLLoaderDataFormat.TEXT;
zipLoader.addEventListener(Event.COMPLETE, onVersionLoaded);
zipLoader.addEventListener(IOErrorEvent.IO_ERROR, onVersionLoadError);
zipLoader.load(new URLRequest(versionURL));
}

private function loadWorkerSWF():void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onWorkerSWFLoaded);
loader.load(new URLRequest("ArchiveUnpackerWorker.swf"));
}

private function onWorkerSWFLoaded(event:Event):void {
var loader:LoaderInfo = LoaderInfo(event.target);
var workerClass:Class = loader.applicationDomain.getDefinition("ArchiveUnpackerWorker") as Class;

// Создаем воркер и прослушиваем события
var workerBytes:ByteArray = new workerClass();
worker = WorkerDomain.current.createWorker(workerBytes, true);
worker.addEventListener(Event.WORKER_STATE, onWorkerStateChange);
worker.start();

// Set up message channels between main thread and worker
var workerInterface:Object = worker.createMessageChannel(Worker.current);
var mainInterface:Object = Worker.current.createMessageChannel(worker);

// Pass necessary data to the worker
workerInterface.send({ archivePath: localFilePath, targetPath: File.applicationStorageDirectory.nativePath + File.separator + "cache/resources" });
worker.setSharedProperty("workerInterface", workerInterface);
worker.setSharedProperty("mainInterface", mainInterface);

// Set up event listener for worker complete event
mainInterface.addEventListener(Event.CHANNEL_MESSAGE, onWorkerComplete);

workerIsRunning = true;
}

private function onWorkerStateChange(event:Event):void {
if (worker.state == WorkerState.TERMINATED) {
workerIsRunning = false;
}
}

private function onWorkerComplete(event:Event):void {
var mainInterface:Object = event.target as Object;
var result:Object = mainInterface.receive();
var success:Boolean = result.success;
// Handle worker completeness and do necessary tasks

// Terminate the worker
worker.terminate();
}

public function onVersionLoaded(event:Event):void {
var remoteVersion:Number = Number(zipLoader.data);

var versionLoader:URLLoader = new URLLoader();
versionLoader.dataFormat = URLLoaderDataFormat.TEXT;
versionLoader.addEventListener(Event.COMPLETE, onLocalVersionLoaded);
versionLoader.addEventListener(IOErrorEvent.IO_ERROR, onLocalVersionLoadError);
versionLoader.load(new URLRequest(versionFile.nativePath));

function onLocalVersionLoaded(event:Event):void {
var localVersion:Number = Number(versionLoader.data);
if (localVersion != remoteVersion) {
startDownloadProcess();
} else {
Alert.showMessage("Local version is up to date");
progressBar.progressBar.visible = false;
// Пропущен код для распаковки архива
}
}

function onLocalVersionLoadError(event:IOErrorEvent):void {
var fileStream:FileStream = new FileStream();
fileStream.open(versionFile, FileMode.WRITE);
fileStream.writeUTFBytes("");
fileStream.close();
startDownloadProcess();
}
}

public function startDownloadProcess():void {
Alert.showMessage("Downloading resources.zip");
progressBar.progressBar.visible = true;
var downloadStream:URLStream = new URLStream();
downloadStream.addEventListener(ProgressEvent.PROGRESS, onDownloadProgress);
downloadStream.addEventListener(Event.COMPLETE, onDownloadComplete);
downloadStream.addEventListener(IOErrorEvent.IO_ERROR, onDownloadError);
downloadStream.load(new URLRequest(resourcesURL));
}

public function onDownloadProgress(event:ProgressEvent):void {
progressBar.setProgress(event.bytesLoaded, event.bytesTotal);
}

public function onDownloadComplete(event:Event):void {
var downloadStream:URLStream = event.target as URLStream;
var fileBytes:ByteArray = new ByteArray();
downloadStream.readBytes(fileBytes);

var fileStream:FileStream = new FileStream();
fileStream.open(new File(localFilePath), FileMode.WRITE);
fileStream.writeBytes(fileBytes, 0, fileBytes.length);
fileStream.close();

var remoteVersion:Number = Number(zipLoader.data);
updateLocalVersion(remoteVersion);
workerIsRunning = true;
}

public function onDownloadError(event:IOErrorEvent):void {
Alert.showMessage("Failed to download resources.zip");
}

public function onVersionLoadError(event:IOErrorEvent):void {
Alert.showMessage("Failed to download resources.zip");
}

private function updateLocalVersion(remoteVersion:Number):void {
var fileStream:FileStream = new FileStream();
fileStream.open(versionFile, FileMode.WRITE);
fileStream.writeUTFBytes(remoteVersion.toString());
fileStream.close();
}
}
} зачем ты убрал код распаковки через воркер не работает