6/29/2010 5:43:35 AM
Title:
Delay Timer in a Preloader
On the fastest connection my preloader goes way to fast... I want to slow it down so the viewer can read the directions on the preloader. I DO NOT want a button.
var myRequest:URLRequest = new URLRequest("123.swf");
var myLoader:Loader = new Loader();
myLoader.load(myRequest);
myLoader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showContent);
var myPreloader:Preloader = new Preloader();
function showPreloader(event:Event):void {
myPreloader.x = (stage.stageWidth /2);
myPreloader.y = (stage.stageHeight /2);
addChild(myPreloader);
}
function showProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
myPreloader.progress_txt.text = "Loading - " + Math.round(percentLoaded * 100) + "%";
myPreloader.image_mc.width = 198 * percentLoaded;
if (percentLoaded>99){
gotoAndPlay(1);
}
}
function showContent(event:Event):void {
MovieClip(myLoader.content).gotoAndPlay(1);
removeChild(myPreloader);
addChild(myLoader);
}
stop();
Davis
Points: 780
Posts:0
6/29/2010 8:52:33 AM
to delay the preloading process create a timer for your delay time in your "showPreloader()" function and put a condition in "showContent()" function which checks if the timer is done then show the content . So if the content loads before the timer say 30 seconds then the content will not be show up by "showContent" function but by the timer function on time complete . Let me know if you have any problem implementing code
6/29/2010 9:58:05 AM
here is the code to delay you preloader. the code below will take care that the content must show up atleast after 20 seconds . If content loads after 20 seconds then content will show up by preloader show content function but if preloader is fast then it will show only after 20 sec
var timer:Timer;
var loadingComplete:Boolean;
var timerComplete:Boolean;
function showPreloader(event:Event):void {
myPreloader.x = (stage.stageWidth /2);
myPreloader.y = (stage.stageHeight /2);
addChild(myPreloader);
//timer 20 sec
timer = new Timer(20000);
timer.addEventListener(TimerEvent.TIMER, timer_timer);
timer.start();
}
function timer_timer(evt:TimerEvent):void {
//20 seconds passed
timerComplete=true;
//if preloader is already finished then show content
if(loadingComplete){
MovieClip(myLoader.content).gotoAndPlay(1);
removeChild(myPreloader);
addChild(myLoader);
}
}
function showContent(event:Event):void {
//preloader finished
loadingComplete=true;
//if preloader completes after timer complete then show content
if(timerComplete){
MovieClip(myLoader.content).gotoAndPlay(1);
removeChild(myPreloader);
addChild(myLoader);
}
}
6/29/2010 10:03:04 AM
Thank You it works perfectly.
6/29/2010 10:21:21 AM
also stop the timer in timer_timer() function using timer.stop() so that it does not keeps on running