package { import flash.display.Sprite; import flash.events.Event; import…
- User
package { import flash.display.Sprite; import flash.events.Event; import launcher.background.Background_Main; import flash.display.StageAlign; import flash.display.StageDisplayState; import flash.display.StageQuality; import flash.display.StageScaleMode; import flash.display.NativeWindow; import flash.geom.Point; import flash.geom.Rectangle; import flash.display.Screen; import zip.ZIPResourceLoader;
/** * ... * @author alekskart */ public class Main extends Sprite { private var guiLayer:Sprite; public var background:Background_Main = new Background_Main(); public function Main() { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); var ziploader:ZIPResourceLoader = new ZIPResourceLoader(); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); this.configureStage(); this.createGUI(); } private function setCenterPosition() : void { var appBounds:Rectangle = stage.nativeWindow.bounds; var screen:Screen = Screen.getScreensForRectangle(appBounds)[0]; stage.stageWidth = 1024; stage.stageHeight = 670; stage.nativeWindow.maxSize = new Point(stage.nativeWindow.width,stage.nativeWindow.height); stage.nativeWindow.minSize = new Point(stage.nativeWindow.width,stage.nativeWindow.height); stage.nativeWindow.x = (screen.bounds.width - stage.nativeWindow.width) / 2; stage.nativeWindow.y = (screen.bounds.height - stage.nativeWindow.height) / 2; } private function configureStage() : void { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; stage.quality = StageQuality.BEST; stage.displayState = StageDisplayState.NORMAL; stage.stageWidth = 1024; stage.stageHeight = 670; this.setCenterPosition(); } private function createGUI() : void { this.guiLayer = new Sprite(); this.guiLayer.addChild(this.background); addChild(this.guiLayer); stage.addEventListener(Event.RESIZE, onResize); } private function onResize(event:Event):void { } }} добавь сюда прогресс бар, который будет просто идти, создай отдельный скрипт для прогресс бара, а в main добавь на сцену
- Assistant
- User
сделай чтобы он шел вперед просто
- Assistant
В классе ProgressBar, замените метод onUpdate с методом ниже:
private function onUpdate(event:Event):void { progress += 0.01; // Увеличьте прогресс на 0.01 каждый фрейм if (progress > 1) progress = 1; // Убедитесь, что прогресс не превышает 1 updateProgressBar(); }
Теперь прогресс бар будет увеличиваться на 0.01 каждый фрейм, пока не достигнет максимального значения 1.
- User
- Assistant
В классе ZIPResourceLoader в методе startDownloadProcess() добавьте следующий код:
private var progressBar:ProgressBar; private function startDownloadProcess():void { Alert.showMessage("Downloading resources.zip"); 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)); progressBar = new ProgressBar(); progressBar.x = (stage.stageWidth - progressBar.width) / 2; progressBar.y = (stage.stageHeight - progressBar.height) / 2; addChild(progressBar); } private function onDownloadProgress(event:ProgressEvent):void { var percent:Number = event.bytesLoaded / event.bytesTotal; progressBar.setProgress(percent); } private function onDownloadComplete(event:Event):void { // ... остальной код ... if (progressBar.parent) { progressBar.parent.removeChild(progressBar); } } private function onDownloadError(event:IOErrorEvent):void { if (progressBar.parent) { progressBar.parent.removeChild(progressBar); } Alert.showMessage("Failed to download resources.zip"); } - User
в ZIPResourceLoader нету сцен, они не поддеживаются, надо сделать в main.as
- Assistant
Понял, в таком случае вы можете передать ссылку на прогресс бар в класс ZIPResourceLoader и обновлять прогресс в методе onDownloadProgress.
В классе Main.as в методе init измените вызов создания объекта ZIPResourceLoader следующим образом:
private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); this.configureStage(); this.createGUI(); var ziploader:ZIPResourceLoader = new ZIPResourceLoader(progressBar); }В классе ZIPResourceLoader добавьте новое приватное свойство progressBar:
private var progressBar:ProgressBar;Измените конструктор класса ZIPResourceLoader для принятия параметра progressBar:
public function ZIPResourceLoader(progressBar:ProgressBar) { this.progressBar = progressBar; // остальной код... }В методе onDownloadProgress обновите значение прогресса прогресс бара:
private function onDownloadProgress(event:ProgressEvent):void { var percent:Number = event.bytesLoaded / event.bytesTotal; progressBar.setProgress(percent); } - User
может не в onDownloadProgress а в startDownloadProcess?
- Assistant
Конечно, вы можете обновить значение прогресса прогресс бара в методе startDownloadProcess вместо onDownloadProgress.
В классе ZIPResourceLoader, в методе startDownloadProcess замените код следующим образом:
private function startDownloadProcess():void { Alert.showMessage("Downloading resources.zip"); var downloadStream:URLStream = new URLStream(); downloadStream.addEventListener(Event.COMPLETE, onDownloadComplete); downloadStream.addEventListener(IOErrorEvent.IO_ERROR, onDownloadError); downloadStream.addEventListener(ProgressEvent.PROGRESS, onDownloadProgress); downloadStream.load(new URLRequest(resourcesURL)); var progressBar:ProgressBar = new ProgressBar(); progressBar.x = (stage.stageWidth - progressBar.width) / 2; progressBar.y = (stage.stageHeight - progressBar.height) / 2; addChild(progressBar); function onDownloadProgress(event:ProgressEvent):void { var percent:Number = event.bytesLoaded / event.bytesTotal; progressBar.setProgress(percent); } function onDownloadComplete(event:Event):void { // ... остальной код ... if (progressBar.parent) { progressBar.parent.removeChild(progressBar); } } function onDownloadError(event:IOErrorEvent):void { if (progressBar.parent) {