PDA

View Full Version : prototype preloader, use it



joyhost
September 28th, 2002, 08: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
September 28th, 2002, 07:56 PM
Nice :)

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

pom :asian:

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

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

pom :asian:

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

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

FlashSwimmer
November 19th, 2002, 03: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
November 21st, 2002, 03:45 AM
Here is a .fla http://www.danalu.com/proto_loader.fla

Ryall
November 22nd, 2002, 04: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
May 12th, 2004, 11: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
July 8th, 2004, 04: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
August 1st, 2004, 11:34 PM
yea, I'd love to see this code too.

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

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

DV81
July 30th, 2005, 06: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
August 30th, 2005, 02: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
November 21st, 2005, 07: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
December 6th, 2005, 11:07 PM
Wouldn't it be:

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

?

kingofnukes
December 27th, 2005, 02: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
March 14th, 2006, 11: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
March 17th, 2008, 11: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