package { import flash.display.Sprite; import flash.display.Shape; import…
- User
package { import flash.display.Sprite; import flash.display.Shape; import flash.events.Event; import zip.ZIPResourceLoader; import flash.events.ProgressEvent;
codepublic class ProgressBar extends Sprite { private var progressBar:Shape; private var backgroundBar:Shape; public var progress:Number; private var maxWidth:Number; private var maxHeight:Number; public var resourceLoader:ZIPResourceLoader; private var bytesLoaded:Number; private var bytesTotal:Number; public function ProgressBar() { init(); } public function setResourceLoader(resourceLoader:ZIPResourceLoader):void { resourceLoader.addEventListener(ProgressEvent.PROGRESS, onProgressUpdate); } public function onProgressUpdate(event:ProgressEvent):void { progress = event.bytesLoaded / event.bytesTotal; updateProgressBar(); } private function init():void { resourceLoader = new ZIPResourceLoader(this); maxWidth = 700; maxHeight = 28; progress = 0; backgroundBar = new Shape(); backgroundBar.graphics.beginFill(0x014ca3); var cornerRadius:Number = 10; backgroundBar.graphics.drawRoundRect(0, 0, maxWidth, maxHeight, cornerRadius); backgroundBar.graphics.endFill(); progressBar = new Shape(); addChild(backgroundBar); addChild(progressBar); addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage); } private function onAddedToStage(event:Event):void { removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); addEventListener(Event.ENTER_FRAME, onUpdate); } private function onRemovedFromStage(event:Event):void { removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage); removeEventListener(Event.ENTER_FRAME, onUpdate); } private function onUpdate(event:Event):void { progress += 0.005; // Увеличьте прогресс на 0.01 каждый фрейм if (progress > 1) progress = 1; // Убедитесь, что прогресс не превышает 1 updateProgressBar(); } public function updateProgressBar():void { progressBar.graphics.clear(); progressBar.graphics.beginFill(0x348aee); var cornerRadius:Number = 3; var yOffset:Number = -2; // смещение по вертикали на 2 пикселя progressBar.graphics.drawRoundRect(0, yOffset, maxWidth * progress, maxHeight + 4, cornerRadius); progressBar.graphics.endFill(); } public function setProgress(value:Number, maxValue:Number = 1):void { progress = value / maxValue; if (progress < 0) { progress = 0; } else if (progress > 1) { progress = 1; } updateProgressBar(); } } - Assistant
To hide the progress bar when the local and remote version.txt files are the same, you can add a conditional statement in the
onLocalVersionLoadedfunction in theZIPResourceLoaderclass. Here's an updated code for that function:actionscriptfunction onLocalVersionLoaded(event:Event):void { var localVersion:Number = Number(versionLoader.data); if (localVersion != remoteVersion) { startDownloadProcess(); } else { Alert.showMessage("Local version is up to date"); progressBar.visible = false; // Hide the progress bar // Пропущен код для распаковки архива } }With this code, if the local version and remote version are the same, the progress bar will be hidden by setting its
visibleproperty to false. - User
мне нужно чтобы скрылся чисто progressBar а не backgroundBar
- Assistant
To hide only the
progressBarinstead of thebackgroundBar, you can modify theupdateProgressBarmethod in theProgressBarclass. Here's an updated code for that method:actionscriptpublic function updateProgressBar():void { progressBar.visible = progress > 0; // Hide the progressBar when progress is 0 progressBar.graphics.clear(); if (progress > 0) { progressBar.graphics.beginFill(0x348aee); var cornerRadius:Number = 3; var yOffset:Number = -2; // смещение по вертикали на 2 пикселя progressBar.graphics.drawRoundRect(0, yOffset, maxWidth * progress, maxHeight + 4, cornerRadius); progressBar.graphics.endFill(); } }With this code, the
progressBarwill be hidden when the progress is 0, and it will be visible and updated with the progress value when it is greater than 0. ThebackgroundBarwill still be visible as usual. - User
progressBar.visible = false; // Hide the progress bar так это скрывает прогресс бар, надо сделать чтобы не весь прогресс бар скрывался целиком а только сама полоса а backgroundBar остался
- Assistant
If you want to hide only the progress bar itself (the colored fill) and keep the background bar visible, you can modify the
updateProgressBarmethod in theProgressBarclass. Here's the updated code:actionscriptpublic function updateProgressBar():void { progressBar.visible = progress > 0; // Hide the progressBar when progress is 0 progressBar.graphics.clear(); if (progress > 0) { progressBar.graphics.beginFill(0x348aee); var cornerRadius:Number = 3; var yOffset:Number = -2; // смещение по вертикали на 2 пикселя progressBar.graphics.drawRoundRect(0, yOffset, maxWidth * progress, maxHeight + 4, cornerRadius); progressBar.graphics.endFill(); } }With this code, the
progressBarwill be hidden when the progress is 0 (no fill will be drawn), and it will be visible and updated with the progress value when it is greater than 0. The will remain visible as usual. - User
ты не правильно меня понял, когда version.txt одинаковый, мне надо сделать чтобы было видно только backgroundBar без progressBar
- Assistant
Apologies for the misunderstanding. If you want to hide the
progressBarcompletely and only show thebackgroundBarwhen the version.txt files are the same, you can modify theonLocalVersionLoadedfunction in theZIPResourceLoaderclass. Here's the updated code:actionscriptfunction onLocalVersionLoaded(event:Event):void { var localVersion:Number = Number(versionLoader.data); if (localVersion != remoteVersion) { startDownloadProcess(); } else { Alert.showMessage("Local version is up to date"); progressBar.visible = false; // Hide the progressBar backgroundBar.visible = true; // Show the backgroundBar // Пропущен код для распаковки архива } }With this code, when the local and remote version.txt files are the same, the
progressBarwill be hidden by setting itsvisibleproperty to false, and thebackgroundBarwill be shown by setting its property to true. - User
надо сделать что что подобное progressBar.progressBar.visible = false;
- Assistant
Apologies for the confusion. In order to hide only the colored fill of the progress bar (
progressBar) while keeping the background bar (backgroundBar) visible, you can modify theupdateProgressBarmethod in theProgressBarclass. Here is the updated code:actionscriptpublic function updateProgressBar():void { progressBar.visible = progress > 0; // Hide the colored fill when progress is 0 progressBar.graphics.clear(); if (progress > 0) { progressBar.graphics.beginFill(0x348aee); var cornerRadius:Number = 3; var yOffset:Number = -2; // vertical offset of 2 pixels var fillWidth:Number = maxWidth * progress; progressBar.graphics.drawRoundRect(0, yOffset, fillWidth, maxHeight + 4, cornerRadius); progressBar.graphics.endFill(); } }