PDA

View Full Version : text field to display % loading ?



fruityDJ
October 4th, 2005, 08:30 PM
Hi
im using the version 8 of flash Pro.
I have this script for my preloader bar which works fine.

How i can add a text field/box so it can display the % percentage loaded ?


var myMCL:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();

myMCL.addListener(myListener);

myListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
var loaded:Number = Math.round((bytesLoaded/bytesTotal) * 100);
progressBar.gotoAndStop(loaded);
}

myListener.onLoadInit = function (target_mc:MovieClip) {
progressBar._visible = false;
}

myListener.onLoadStart = function (target_mc:MovieClip) {
progressBar._visible = true;
}

myMCL.loadClip("main_movie.swf","container");

TheCanadian
October 4th, 2005, 08:55 PM
Create a dynamic text box with the var loaded. That's it :).

If you want a percent sign beside it, give the text box the var perLoaded and use this code on the root time line with the rest of your code:
var perLoaded = loaded + "%";

fruityDJ
October 4th, 2005, 09:04 PM
thanks Canadian,
do i give the "perLoaded" at the instance of text box or at the var field ?

thanks though, gonna try it now

TheCanadian
October 4th, 2005, 09:05 PM
thanks Canadian,
do i give the "perLoaded" at the instance of text box or at the var field ?

thanks though, gonna try it now
Glad I could help. Give the text box the var perLoaded :).

fruityDJ
October 4th, 2005, 09:12 PM
ok ive put it like this:


var myMCL:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
var perLoaded = loaded + "%";

myMCL.addListener(myListener);

myListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
var loaded:Number = Math.round((bytesLoaded/bytesTotal) * 100);
progressBar.gotoAndStop(loaded);
}

myListener.onLoadInit = function (target_mc:MovieClip) {
progressBar._visible = false;
}

myListener.onLoadStart = function (target_mc:MovieClip) {
progressBar._visible = true;
}

myMCL.loadClip("main_movie.swf","container");


but when i test the movie on the text box it tells me:
"undefined %"

?

TheCanadian
October 4th, 2005, 09:16 PM
That's because the var tag infront of loaded constrains it to that function. Try this :):



var myMCL:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();


myMCL.addListener(myListener);

myListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
var loaded:Number = Math.round((bytesLoaded/bytesTotal) * 100);
progressBar.gotoAndStop(loaded);
var perLoaded = loaded + "%";
}

myListener.onLoadInit = function (target_mc:MovieClip) {
progressBar._visible = false;
}

myListener.onLoadStart = function (target_mc:MovieClip) {
progressBar._visible = true;
}

myMCL.loadClip("main_movie.swf","container");

fruityDJ
October 4th, 2005, 09:21 PM
now it dosent show up at all ;(

TheCanadian
October 4th, 2005, 09:39 PM
I'm not very good with listeners so I'm just guessing. Try this :):


myListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
var loaded:Number = Math.round((bytesLoaded / bytesTotal) * 100);
progressBar.gotoAndStop(loaded);
perLoaded = loaded + "%";
};

fruityDJ
October 4th, 2005, 09:45 PM
Ur the man.
It worked !!
Just a simple thing left.
How to hide the text field after its loaded since it shows on top of loaded content ?

fruityDJ
October 4th, 2005, 09:48 PM
Dont worry mate..found it :cool:
I gave it an instance name and set the visible to false.

Thanks alot for your help.