OK,here’s the new code,this one at least works,but you have to hit Ctrl+Enter two times(so basically reload it).Any ideas how to make it work the first time around?
stop();
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.*;
this.stop();
var image:Loader = new Loader();
var loaded:TextField = new TextField();
var loadedFormat:TextFormat = new TextFormat();
var progressBar:MovieClip = new MovieClip();
var preloader:MovieClip = new MovieClip();
var masker:MovieClip = new MovieClip();
var fadeOutTween:Tween;
var percent:Number;
var imageHeight:Number;
var style:String;
var opacity:Number;
image.load(new URLRequest("image.jpg"));
image.contentLoaderInfo.addEventListener(Event.COMPLETE, Graph);
function Graph(event:Event):void
{
preloader.addChild(image);
imageHeight = image.height;
masker.graphics.beginFill(0xffffff);
masker.graphics.drawRect(0,0,image.width,image.height);
masker.graphics.endFill();
masker.alpha = 0.5;
preloader.addChild(masker);
loaded.width = image.width;
loaded.height = 20;
loaded.y = image.height;
loaded.text = "Loading... 0%";
loaded.selectable = false;
loadedFormat.align = TextFormatAlign.CENTER;
loadedFormat.font = "Verdana";
if(image.width<100)
{
loadedFormat.size = 9;
}
else if(image.width<200)
{
loadedFormat.size = 10;
}
else
{
loadedFormat.size = 11;
}
loadedFormat.bold = true;
loaded.setTextFormat(loadedFormat);
preloader.addChild(loaded);
preloader.x = stage.stageWidth/2-preloader.width/2;
preloader.y = stage.stageHeight/2-preloader.height/2;
addChild(preloader);
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,Loading);
}
function Loading(event:ProgressEvent):void
{
percent = Math.round((event.bytesLoaded/event.bytesTotal)*100);
loaded.text = "Loading... "+percent+"%";
loaded.setTextFormat(loadedFormat);
preloader.addChild(loaded);
masker.height = imageHeight-imageHeight/100*percent;
if(percent == 100)
{
fadeOut();
}
}
function fadeOut():void
{
preloader.removeChild(loaded);
fadeOutTween = new Tween(preloader,"alpha",None.easeOut,1,0,3,true);
var timer:Timer = new Timer(3000,1);
timer.start();
timer.addEventListener(TimerEvent.TIMER_COMPLETE, proceed);
}
function proceed(event:TimerEvent):void
{
gotoAndStop(2);
}
My suspition is on the this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,Loading); line,but it might be something else.Thanks in advance.