PDA

View Full Version : Preloader problem



pete_zahut
September 10th, 2003, 05:10 PM
Hi,

I just made a full flash site, and I did that with loading other swf's into it. So if you press a button this is the code:

on(release){
loadMovie("test.swf",/Load);
}

That "Load" thing is an empty movieclip.

Now I finished my site, I realised it doesn't have a preloader... can anyone help me? I allready tried the tutorial on this site, but I can't make it work.. I just don't know where to place the code...

Thx

Eric Jr.
September 10th, 2003, 06:01 PM
Had the same problem once, fixed it with a simple script that draws a preloader bar with the API, I hope posting this will help, but too be honest, I think it won't. Sorry...

Anyway, put this script in a movieclip.
And put that movieclip onto the Stage. (Frame one) give it this instancename: "preloader"


movieWidth = 550;
movieHeight = 400;
width = 200;
height = 10
font = 'Arial';
fontsize = 10;
borderColor = '0x000000';
innerColor = '0x000000';

this.createEmptyMovieClip("border", 1);
with (this.border) {
lineStyle(0, borderColor);
moveTo(0, 0);
lineTo(width, 0);
lineTo(width, height);
lineTo(0, height);
lineTo(0, 0);
//
this.createTextField("percent", 0, 0, height, width, height*2);
myformat = new TextFormat();
myformat.color = 0x000000;
myformat.align = "center";
myformat.font = font;
myformat.size = fontSize;
percent.selectable = false;
percent.setTextFormat(myformat);
//
_visible = false;
}
this.border.createEmptyMovieClip("loadbar", 1);
with (this.border.loadbar) {
beginFill(innerColor, 100);
moveTo(2, 2);
lineTo(width-1, 2);
lineTo(width-1, height-1);
lineTo(2, height-1);
lineTo(2, 2);
endFill();
_xscale = 0;
}
_root[targetMovie]._visible = false;
_root.timer = getTimer();
this.onEnterFrame = function() {
if (loading) {
with (this.border) {
_visible = true;
percentLoaded = Math.round(_root[targetMovie].getBytesLoaded()/_root[targetMovie].getBytesTotal()*100);
bytesOfbytes = Math.round(_root[targetMovie].getBytesLoaded()/1024) + " / " + Math.round(_root[targetMovie].getBytesTotal()/1024) + " Kbytes loaded...";
loadbar._xscale = percentLoaded;
percent.text = bytesOfbytes;
percent.setTextFormat(myformat);
if ((getTimer() - _root.timer > 5000) && (percentLoaded != Number ))
{
removeMovieClip("border");
percent.html = true;
percent.htmlText = "<B>Error: </B><font color='red'>FILE NOT FOUND!</FONT>";
percent.setTextFormat(myformat);
delete this.onEnterFrame;
}
}
if (percentLoaded == 100) {
loadMovie(_root.location, _root);
}
}
};



Then create the movieclip, and load the .swf into it (first two lines)
The last to lines tell the preloader which movie should be loaded, and to do the actually loading.


_root.createEmptyMovieClip( "swf", 0 );
loadMovie(_root.location, _root.swf);
_root.preloader.targetMovie = _root.swf;
_root.preloader.loading = true;
stop();

Eric Jr.
September 10th, 2003, 06:01 PM
I know .. I could explain things better or rather post a .fla.
But i'm tired now, and I'm going to bed :)

pete_zahut
September 11th, 2003, 04:20 AM
Thx, I'll trie it out. And if it doesnt work, I'll let you know

Eric Jr.
September 11th, 2003, 05:53 AM
Deal :p:

ave
September 11th, 2003, 09:32 AM
ok here is a really simple preloader which works on anything, not as sophisticated or complex as the ablove solution:beam:
but i like to keep things as simple as possible personally ...


this.bar._visible=false;
this.onEnterFrame = function() {
if (this.getBytesLoaded()<this.getBytesTotal()) {
this.bar._visible=true;
Total = this.getBytesTotal()/1000;
Received = this.getBytesLoaded()/1000;
Percentage = (Received/Total)*100;
this.bar.barmc._xscale = int(Percentage);
} else {
this.gotoAndPlay("into");
this.onEnterFrame = null;
this.bar._visible=false;
}
}


Then you just have an instance of the "this.bar" clip on main stage in frame one on its own before the intro animation or whatever u have.
Then if the preloader is needed it shows if not it just skips that frame without ever showing the "this.bar" clip.
You can use this on object/loaded and level/loaded clips so very versatile.

Hope its of some use :)

Eric Jr.
September 11th, 2003, 10:58 AM
How is it appliable on different objects and clips while you specify a this.onEnterFrame and call the Loaded bytes of that object?
That would mean he has to put a preload in each .swf, thats not what I did, just one script for all exernal .swf's...

And its not sophisticated or complex ...

ave
September 11th, 2003, 11:10 AM
you just put the code at the begining of each clip (the ones being loaded in) and this then automatically targets the loaded movie , try it ...im sure it works...
and yes as i said its not as sophisticated as your solution (as mine requires adding that code and a bar clip to each movie you are loading) this is exactly why i said its not as complex or sophisticated as yours :)

And yes to me and im sure others too it is complex (im sure i could pick it apart eventually but it would take me a while with my limited knowledge of drawing API)
so i was simply offering the guy a simpler easier to grasp solution, not saying either is better or worse or anything :)

just im more of a designer than a coder so i like to try to keep my AS simple

Eric Jr.
September 11th, 2003, 12:00 PM
well thats a pain aswell, having to put it in each clip you load a movie in, but fair enough .. I just like the API :)

pete_zahut
September 13th, 2003, 05:23 AM
Euhm Eric Jr,

i can't make it work.. where do i have to put the last bit of code?

:block:

Eric Jr.
September 13th, 2003, 07:45 AM
Just put that on the main timeline. The rest of the code should go into a MC called "preloader" ...

ave
September 13th, 2003, 10:11 AM
hehe the above is exact reason i like my nice and simple preloader :) i understand it and it works for me, i dont like using code which i cannot understand fully even if it is good.

Although i must say good work on your preloader it is very good, maybe you should write a tutorial on it or something its quite unique , an API preloader well at least i havent seen one before

pete_zahut
September 13th, 2003, 02:16 PM
ok, i'll check it out. And ave i'll trie yours too... :rd: