How do I combine the preloader transition with the preloader percentage bar?

Hi guys,

Got to say what a great site, i’ve learnt so much since i’ve discovered it!

I’m still having trouble getting my head around AS.

What I want to do is use a transition when loading external files into my main flash site, as described here:

http://www.kirupa.com/developer/mx/preloader_transition.htm

but while the’re loading I want to show a percentage bar, as per this tut:

[color=#003366]http://www.kirupa.com/developer/mx/percentagepreloader.htm[/color]

I’m pretty sure its got something to do with combining this AS:


onClipEvent (enterFrame) {	
if (!loaded && this._url != _root._url) {	 
if (this.getBytesLoaded() == this.getBytesTotal()) {
loaded = true;			
_root.transition.gotoAndPlay("opening");		
}	
}
}

with this:


bytes_loaded = Math.round(this.getBytesLoaded());
bytes_total = Math.round(this.getBytesTotal());
getPercent = bytes_loaded/bytes_total;
this.loadBar._width = getPercent*100;
this.loadText = Math.round(getPercent*100)+"%";
if (bytes_loaded == bytes_total) {	
this.gotoAndPlay(3);} 

I’ve tried playing around with combining them, but i just cant get my head around it.

I know its probably simple, but if anyone can tell me how to do it I’d be most greatfull.

Thanks

in the transition movieclip:
add in some extra frames to do the calculations and another layer to hold the percentage bar.
the new frames should go in the middle of all the motion tweens, and after the frame on the actions layer that loads the movie in the content movie clip.

Thanks for the reply,

But it the AS i’ve got trouble with, i’m trying something like this:

onClipEvent (enterFrame) {
 bytes_loaded2 = Math.round(this.getBytesLoaded());
	bytes_total2 = Math.round(this.getBytesTotal());
	getPercent2 = bytes_loaded2/bytes_total2;
 if (!loaded && this._url != _root._url) {
   this.loadBar2._height = getPercent2*80;
		 this.loadText2 = Math.round(getPercent2*100)+"%"
  if (bytes_loaded == bytes_total) {
   loaded = true;
   _root.transition.gotoAndPlay("open");
  }
 }
}

I can’t get the AS to read how much is left of the external .swf and convert into a bar.

Thanks

that’s a pretty complicated way of doing it.
make a rectangle, convert it to a MovieClip and give it an instance name of something like loaderBar, which is what i will use.
This goes in the frame after the frame which loads the content into the _root.content movieclip.

percentloaded = (_root.content.getBytesLoaded() / _root.content.getBytesTotal())*100;
loaderBar._xScale = Math.round(percentLoaded);

in the next frame, we want to see if the movie has completed loading, so we use this simple test:

if (_root.content.getBytesLoaded == _root.content.getBytesTotal) {
_root.transition.gotoAndPlay("open");
} else {
gotoAndPlay(_currentFrame-1);
}

also, i should point out, the loaderBar should be on a seperate layer from the actionscript because it must last over the 2 frames of the actions, and must not be seperated into keyframes.

sort of like this…
[note: you will need the other files that came with the original file from here.]

sort of like this:
i have not included the other .swf files, you can get them from the transition tutorial here: http://www.kirupa.com/developer/mx/preloader_transition.htm

ok, thanks for that.

This is gonna take some tinkering.

I also have a preloader before the main file has loaded.

The transition preloader doesn’t seem to work when I have the main preloader as well!

Ok, I think I have this working now, my connection is too fast for me to be sure!!!

Thanks for all the help Cyberathlete.

:thumb:

Glad to help (-:

Dear helpers,

I thought I was nearly there with this and was feeling very happy with myself but, after combining the two tutorials into one, I find that not only do the external swf’s not load, but the ‘transition’ MC doesn’t play either!

Is this a targeting issue and the fact that I’ve added a new scene with frames? Does the _root mean the main timeline, and would that be part of the problem?

I’m a bit of a lightweight when it comes to AS and need to be told in a similar way to speaking to a very young child! :slight_smile:

Any help would be greatly apreciated.

lol. yes, _root is the main timeline. everything is on this timeline, in some way or another. eg:
_root -> movie1
_root -> movie1 -> movie2 -> movie3

you see?
As to answer your question - “would that be part of the problem?” - who knows? how exactly are you using as in your scripts?

a bit more information would be useful :).
if you get stuck, there’s already an example there with the completed preloader bar + transition. you can use it as an example of how to do it.

Thanks for the reply cyberathlete.

I have attached the files that I am having trouble with. Any chance of quickly glancing at them and seeing if the problem has a straightfoward answer?

thanks mate

Thanks for the reply cyberathlete. I have attached the .fla file I’m having problems with. I have excluded the external .swf’s due to the maximum file size allowed to attach. I fully understand if you are unable to have a look at this, but would be very grateful if you could cast an experienced eye over it and have a quick shuffties to see if there is an obvious problem.

Yours in anticipation

Twang