PDA

View Full Version : prototype preloader, use it


joyhost
09-28-2002, 07:51 AM
How about a good prototype preloader?
U just type
holder.loadhere(x,y,"somemovie.swf","nameofmovie");It will show a loading bar and preload your movie into holder movieclip.
Just copy-paste this code to your first frame, first scene.
Then use in root or in an instance.
eg. mc1.loadhere(0,0,"pic1.jpg","pic1")
then the path of the loaded movie is _root.mc1.pic1

Maybe the code is a little bit dirty :x
If you have a question or suggestion.... post it!

movieClip.prototype.loadhere=function(x,y,path,nam e) {

// creates and positions clip, bar and text
var containerText=name+"text";
var containerBar=name+"bar";
this.createEmptyMovieClip(name,1);
this.createEmptyMovieClip(containerText,2);
this.createEmptyMovieClip(containerBar,3);
this[name]._x=x;
this[name]._y=y;
this[containerText]._x=x;
this[containerText]._y=y;
this[containerBar]._x=x;
this[containerBar]._y=y;

// draws the bar
with (this[containerBar]){
beginFill (0xDDDDDD, 50);
lineStyle (1, 0x000000, 100);
moveTo (0, 0);
lineTo (80, 0);
lineTo (80, 20);
lineTo (0, 20);
lineTo (0,0);
endFill();
}

// loads movie
this[name].loadMovie(path);
var movie=this[name];
var prelText=this[containerText];
var prelBar=this[containerBar];

// sets new text format
var formtext=new TextFormat();
formtext.color="0x000000";
formtext.font="_sans";
formtext.align="center";
prelText.createTextField("loadtext",50,0,0,80,20);
prelText.loadtext.border=false;

// defines text display
prelText.onEnterFrame=function() {
if(this.percent!=100) {
this.percent=int((movie.getBytesLoaded()/movie.getBytesTotal())*100)
this.loadtext.text="Loading "+this.percent+"%";
this.loadtext.setTextFormat(formtext);
prelBar._xscale=this.percent;
}
if(this.percent==100) {
delete this.onEnterFrame;
this.removeMovieClip();
prelBar.removeMovieClip();
}
}
}
//end prototype
Make sure you run it in server enviroment just to see preloader, or using xat.com WebSpeed simulator (not advertising it)

pom
09-28-2002, 06:56 PM
Nice :)

I'm putting this in the best of Kirupa if you don't mind.

pom :asian:

calaway42
09-28-2002, 07:05 PM
joyhost, if it's possible can you post the fla for the preloader plz ?! :D thanx

pom
09-29-2002, 06:37 AM
It's all-code!! What do you need a fla for? :P :P

pom :asian:

FlashSwimmer
11-18-2002, 05:15 PM
i'm missing something to make it play.... :(
can anyone HELP C:-)

telekinesis
11-18-2002, 06:25 PM
What are you talking about? Are you saying that your externally loaded movie stops at your first frame.....

FlashSwimmer
11-19-2002, 02:19 PM
what i mean is i don't know how make this preloader play to use it. :(
if you did it before, it'll be greate if you send me .fla file =)
thanx

telekinesis
11-21-2002, 02:45 AM
Here is a .fla http://www.danalu.com/proto_loader.fla

Ryall
11-22-2002, 03:16 AM
isnt the beauty of prototypes, classes, and the like that they can be used in any situation in any fla and get the same result - hmmm :smirk:

No offense, just playin'

Peace

ghjr
05-12-2004, 10:47 AM
Any idea why this won't work in Flash Player 7? It only seems to be working on 6 for me...

If I find out I'll post here.

dallas
07-08-2004, 03:56 AM
Here is a .fla http://www.danalu.com/proto_loader.fla


Could you post the fla again so that I can see where the code actually resides please.... it sound great

InsaneleSS
08-01-2004, 10:34 PM
yea, I'd love to see this code too.

KaiserSouze
09-09-2004, 01:09 PM
One quick question, is it possible to reference embeded fonts for the text, instead of using system fonts?

3jorn
04-29-2005, 11:47 AM
Kaiser - Just choose the text you have written in any font click on character -> specify ranges and choose the 4 on the top.

DV81
07-30-2005, 05:04 AM
hi guys !, wonderful pice of coding their :)

just a quick fix i found regarding his code on the very first line

movieClip.prototype.loadhere=function(x,y,path,nam e) {

should read

MovieClip.prototype.loadhere=function(x,y,path,nam e) {

basically the word movieClip should be capital M "MovieClip" and his last parameter name was written "nam e"

not being a critique just spent a good 1 hour or so figuring that out just incase someone else is interested cheers !!!

eurosickwitit
08-30-2005, 01:10 AM
well yeah, seemed very straightforward, i saw it the first minute i tested it

but no offense here, just sayin, good work, nice all code preloader

sAi
11-21-2005, 06:48 PM
am I mentally challanged? why doesn't this work for me...

frame 1: prototype (with corrections)
frame 2: stop();
holder.loadhere(58, 40, "test.swf", "pages");

and I've created a mc and dragged it onto the stage with an instance name of "pages"

?????

kingofnukes
12-06-2005, 10:07 PM
Wouldn't it be:

pages.loadhere(58, 40, "test.swf", "test");

?

kingofnukes
12-27-2005, 01:07 PM
OK, I've tried using this for myself now and it works great! Thanx.
But I need some help designating how to conbtrol the loaded MovieClip.
I tried using holder as the instance name (along with the neccessary _roots)
and I also tried a holder.Movie1 but I just can't get my Movie controler to work for it. What am I doing wrong?

PS Sorry for the double post, but this is a totally diffrent topic.

Thanks for the help. :)

Gupps
03-14-2006, 10:46 AM
king of nuke, can u share you fla. i'm having a hard time figuring this out. it give me an error of

**Error** C:\Documents and Settings\Siu Ling\Desktop\proto preloader\holder.as: Line 57: ActionScript 2.0 class scripts may only define class or interface constructs.
//end prototype

kubana
03-17-2008, 10:52 AM
This looks very interesting.
Does anyone still have the file for it?
If yes please can you post it or give the link.

Thank you