Althought I set the download simulation to the slowest option, it will only hold empty screen for a while and then print 100% text.
Heres the code I use (as a main class):
Code:
package {
import flash.events.*
import flash.display.Sprite;
import flash.text.*
public class Base extends Sprite {
private var loadBar:Sprite;
private var _tf:TextField;
private var _fmt:TextFormat;
public function Base() {
preload();
}
private function preload() {
this.loaderInfo.addEventListener(Event.COMPLETE, initApplication);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
with (this.graphics) {
beginFill(0xFFFFFF)
drawRect(10,stage.stageHeight-50,300,10)
}
loadBar = new Sprite()
addChild(loadBar)
_fmt = new TextFormat("_sans", 11, 0xCCCCCC);
_tf = createText();
addChild(_tf);
_tf.x = 9
_tf.y = stage.stageHeight - 40
}
private function showProgress(e:ProgressEvent):void {
var percent:Number = Math.round((e.bytesLoaded / e.bytesTotal )*100 );
trace(percent + " %");
with (loadBar.graphics) {
clear()
beginFill(0x000000)
drawRect(10,stage.stageHeight-50,3*percent-2,8)
endFill()
}
_tf.text = "Loading: "+ percent + " %"
}
private function initApplication($e:Event):void {
this.graphics.clear()
loadBar.graphics.clear()
_tf = null
new Application()
}
private function createText():TextField {
var t:TextField = new TextField();
t.width = 0;
t.height = 0;
t.autoSize = TextFieldAutoSize.LEFT;
t.selectable = false;
t.defaultTextFormat = _fmt;
return t;
}
}
Any idea what am I doing wrong?
Many thanks for help!