header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Del
Points:0
Posts:0
Answered

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();





1
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

2
Umesh
Points: 0
Posts:0
Accepted Answer
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);  
	}
}  


3
Del
Points: 0
Posts:0
6/29/2010 10:03:04 AM



Thank You it works perfectly.

4
Umesh
Points: 0
Posts:0
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


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 4+1 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions