PDA

View Full Version : A preloader class


retrotron
05-13-2003, 09:43 PM
I've finally decided to put some preloader code into a class so I can reuse it whenever needed. My preferred practice is to do the preloading without any frameloops. I would like to be able to simply apply a preloader object to any given movieclip which contains a loading .swf or .jpg. Presumably, that's what this class does.

Here's my class so far, but I'm not sure if it is working or not. Perhaps anyone can tell me if this is good or not, or maybe a better way to do it OO-wise?


// ************************************************** ****************
// define Loader Class Constructer
function Loader(name,parent,target,targetDepth) {
this.name = name;
this.parent = parent;
this.target = target;
this.depth = targetDepth + 1;
} // end Loader Class Constructer

Loader.prototype.drawLoader = function() {
_root.createEmptyMovieClip("loader_mc",this.depth); // create empty loader_mc
this.depth += 1; // increment the depth 1
with (_root.loader_mc) {
// draw background box
lineStyle(1,0x000000,100);
beginFill(0xffffff,80);
moveTo(0,0);
lineTo(200,0);
lineTo(200,50);
lineTo(0,50);
lineTo(0,0);
endFill();
// create text fields
var loaderFormat = new TextFormat();
loaderFormat.font = "arial";
loaderFormat.size = 11;
// create "loader" textfield
createTextField("loader_txt",this.depth,10,25,100,20);
this.depth += 1; // increment depth 1
loader_txt.html = true;
loader_txt.htmltext = "loaded: ";
loader_txt.setTextFormat(loaderFormat);
// create "loaded" textfield
createTextField("loaded_txt",this.depth,30,25,162,20);
loaded_txt.html = true;
// create loader bar
createEmptyMovieClip("loaderBar_mc",depth);
this.depth += 1; // increment depth
loaderBar_mc.lineStyle(1,0x000000,100);
loaderBar_mc.moveTo(10,20);
loaderBar_mc.lineTo(190,20);
} // end with grouping
} // end Loader.drawLoader() method definition

Loader.prototype.runLoader = function() {
this.drawLoader(); // draw the loader
// run this.loadCheck() every 1 milliseconds
this.loadInterval = setInterval(this.loadCheck,1,this.target,this.name );
} // end Loader.runLoader() method definition

Loader.prototype.loadCheck = function(x,y) {
// x: the path to the target which is being loaded
// y: the name of the current Loader instance
// check if all bytes are loaded
var loadBytes = eval(x).getBytesLoaded();
var totalBytes = eval(x).getBytesTotal();
var percentLoaded = (loadBytes/totalBytes) * 100;
// set the values of the "loaded_txt" text field
var loadedFormat = new TextFormat();
loadedFormat.font = "arial";
loadedFormat.size = 11;
loadedFormat.align = "right";
with (_root.loader_mc) {
loaded_txt.htmltext = loadBytes + "/" + totalBytes + "bytes";
loaded_txt.setTextFormat(loadedFormat);
loaderBar_mc._xscale = percentLoaded;
} // end with grouping
if (totalBytes == 0) {
// do nothing, execute Interval again
} else {
if (loadBytes < totalBytes) {
// do nothing, execute Interval again
} else {
clearInterval(eval(y).loadInterval); // stop the interval
// leave this commented for debugging purposes
// _root.loader_mc.removeMovieClip();
} // end "if loadBytes < totalyBytes"
} // end "if totalyBytes == 0"
} // end Loader.loadCheck() method definition

// end Loader Class definition //
// ************************************************** ****************


// test the loader
// ---------------------------------------------

// create a "holder" clip
this.createEmptyMovieClip("holder_mc",0);

// load the .jpg
this.holder_mc.loadMovie("eastAsia2.jpg");

// create and run the preloader object
var myLoader = new Loader("myLoader",this,"_root.holder_mc",0);
myLoader.runLoader();
As you can see, to test it, I simply load some image or .swf into holder_mc, then create a new Loader object and run the "runLoader()" method.

Any ideas on why this is not working or how to do it better?

retrotron

retrotron
06-05-2003, 05:04 AM
Been a while since I looked at this post, but it looks like nobody ever replied here. If a search turns this thread up, it was resolved here: http://www.flashkit.com/board/showthread.php?threadid=453087

CyanBlue
06-05-2003, 06:04 AM
Um... Um... You should have said it abit earlier... :(

Okay... The replies from the cancerinform at the FK doesn't make any sense to me at all at the moment... I guess I've been sitting in front of the computer way too long... :D

Here is the version that I have done... Here is what I have done... I have used your structure and function name and all and used that to mimic OOP with the code that I have been working on which is basically from the FlashGuru's... Don't you think I am good at sawing things??? :D

http://www.cfhosting.it/CyanBlue/Tests/Preloader/Preloader03.html
http://www.cfhosting.it/CyanBlue/Tests/Preloader/Preloader03.zip

I still need to figure out how to know if there is any library item with the given linkage identifier or not, but that file is basically working under the condition that the font exists in the library...

Tell me what you think... ;)

retrotron
06-05-2003, 02:09 PM
Nice preloader. I downloaded it of course. :) I see you got the cfhosting thing working. Isn't it nice to have no ads?

As for checking whether AS can know about library symbol, see this discussion: http://chattyfig.figleaf.com/ezmlm/ezmlm-cgi?1:sss:74066#b. My guess is this isn't possible. :(

CyanBlue
06-05-2003, 03:55 PM
Yeah... My bet is that it isn't possible as well, but I had to ask... It's just that I want to use some specific font for the text in the preloader and if that doesn't exist, then to replace it to something else that's present in the library... As you can see that I have argument for the font name and font size, and if I cannot use that font, now I cannot because I cannot embed the specific font to the library automatically, then it's moot...

Oh, anyways... Can you check a couple of things for me???
I see that mine is somewhat stealing the CPU power or something... If I have two windows up, and one being the preloader and another one being the AS.org forum area... If I use ALT-TAB to go back and forth between the windows, I get to see the screen refresh real slow on the preloader, yet I don't have that problem with your preloader that I have got from the FK... I just want to know if that problem exists in your computer as well...

Another one is straight forward... How OOP or procedural is that code??? :D

I get to hurry out to go to the hospital... My wife has a doctor's appointment and I'll be back...

Thanks for the check!!! :)

subquark
06-05-2003, 04:08 PM
yeah, but . . . will the preloader class thing (what is a class?) work with annoying "export for AS in first frame" components in the movieclip? I mean, start at 0%?

:confused:

retrotron
06-05-2003, 04:54 PM
Hey subquark,

The preloader class (I'll explain a class in a sec) I posted is just code, nothing in the library at all. You past it in and it runs, creating everything as it needs. So there's no need to export because there won't be anything in the library, the code does it all.

However, in the FlashKit thread, cancerinform did turn it into a component that has a symbol in the library. Either way, it does start at 0 and climbs from there, but it's usually so fast you never see the 0. By the time you see it, it's already up to 10bytes or whatever.

Actually, it's not in %, it's in bytes, but that's easy to change. One of these days I might update that preloader class and let the user define colors, fonts, sizes, bytes/Kbytes/percent, etc. Right now I don't use this preloader class, I just code a preloader into whatever it is I'm working with. I guess the real use of it at this point is just seeing some code that does what a preloader is supposed to do. On the other hand, CyanBlue's preloader is looking real slick and is easier to use. It will have a symbol in the library too, if that makes things easier. That's definitely a good choice.

I feel like I'm being vague here. :(

Anyways, a "class" is a technical term that falls under the "Object Oriented Programming" (OOP) heading. Check out my post titled "OOP 101?" here: http://www.actionscript.org/forums/showthread.php3?s=&threadid=27509&perpage=15&pagenumber=2

If it doesn't make any sense, feel free to ask as many questions as you like. :)

retrotron
06-05-2003, 05:31 PM
CyanBlue, When I switch between as.org forums and your preloader, the preloader works the same for me as if it were just the preloader working. The one place it is a bit jerky is the first and last 15% of loading. But that's not a screen refresh for me, it's just a lag in the data loading.

As for OOP, your Preloader03.fla . . . . that's OOP baby!!

CyanBlue
06-05-2003, 08:00 PM
Huh... That's an OOP??? :D

Well... As I was saying basically used your structure with FlashGuru's routine... So, it's all you guys'... :)

So... I have a question... :D

I call the loader like this...var myLoader = new Loader("myLoader", this, "_root.holder_mc", "Ranch.jpg", 100, 75, "Bauhaus Lt BT", 14, 0);and if I say 'this' within this block,Loader.prototype.runLoader = function()that means the myLoader instance, right???

And if I say 'this' within this block,Loader.prototype.loadCheck = function(x, y)that means the myLoader instance as well, right???

Why ask??? I was not able to clear the interval with 'this' and I ended up using '_global.loadInterval' instead... Can you tell me why??? ;)

CyanBlue
06-05-2003, 08:01 PM
Um... Forgot to say that...

In terms of the screen refresh thing... You don't really see it, right??? I guess it is just my slow computer and the slow 56k combination then... ;)

retrotron
06-05-2003, 09:10 PM
Yeah, "this" refers to the instance everytime you use it in the constructor function or functions attached to the constructor function's prototype. I think that's one of the reasons that compels me to use OOP, it's so nice and easy to just use "this" instead of trying to keep track of the instance. Nice work!

As for your setInterval, intervals are called with a null scope, so "this" (and any other scope-dependent reference) returns undefined if it's inside a function that is called by setInterval(). However, funny that you asked, senocular just told me that you can call setInterval inside a specific object's scope (see this thread: http://www.actionscript.org/forums/showthread.php3?s=&threadid=29031). Your _global method works fine, or you can use the "setInterval(object, function, interval, parameters)" syntax.

sneeuwitje
06-05-2003, 09:24 PM
Any of you ran this thing through the debugger yet?

'myLoader.parent' gets 'myLoader' copied into itself to infinity. Anyways: i didn't reach the end...). My guess ... is that can't be good for the player.
Guess aswell that it's the cause of CyanBlue's trouble on switching sites: these things only seem to really hit you when the connection is slow, and then it hits goood ...

don't understand how and why. You guys seem to be much more into this than i am.

CyanBlue
06-05-2003, 09:32 PM
Howdy, sneeuwitje... ;)

Thanks for reminding me of that...

Yes... I have seen it, and I was meaning to ask retrotron why he used 'parent' argument and I forgot... :)

Tell me why you have that argument, retrotron... I just left it there because I wasn't sure why you wanted it there... ;)

subquark
06-05-2003, 09:46 PM
sorry, I was not clear :( . The preloader, um, when you use a component, such as scrollpane, it has to be set to export in first frame which means that it loads before the preloader gets a chance to start. So it's easy to have at least 16KB load before the prelaoder gets visible. For those of us on dial-up, that can be 4 or 5 seconds. So how do I use a preloader to do this? A separate preloader swf that gets Bytes? (gee that bites)

Probably a basic question, but then again, I'm a basic-kinda-baby-havin'-guy!:D

sneeuwitje
06-05-2003, 09:54 PM
So that makes a good reason to make this thing a component after all. Only how do you get it to load as the very 1st one?

Or maybe MM should implement this preloader class in actionscript?

retrotron
06-05-2003, 10:26 PM
Thanks for the tip sneeuwitje. That's definitely good to know.

I took a look at the debugger and here's what I think is happening, though this is just a shot in the dark:

myLoader.parent refers to one level above myLoader, but the debugger doesn't know how to represent this visually. It only knows how to show children of children. i.e. it doesn't know how to list something which is a property of an object (myLoader.parent) but evaluates to the parent of that object.

Instead, it just says "oh, myLoader.parent refers to this parent", so it lists the parent, but then it lists all the children of the parent, and of course myLoader is one of those children, so myLoader gets listed again. You can expand this one and get myLoader.parent again, and again it doesn't know to show you that this evaluates to the parent, and so on ad infinitum.

I bet this will happen everytime you have a variable or property of an object that evaluates to the parent of that object.

I'm not sure if that's really what's happening, but I hope that's what it is, because otherwise you're right, it can't be good for the Flash player.

What do you think?

retrotron
06-05-2003, 10:36 PM
Ah, to answer why I use parent in there, it's just so I know what the parent is from within the class. The only real time this comes in handy, I think, is if you need to delete an instance from within itself. You can't use "delete this" because of the scope. You have to delete it from the parent. You can use "delete _root.myLoader;", but then you have to know the name of the instance (delete _root[this.name];) and the parent (delete ????[this.name];). This has been discussed at flashcoders a lot, and I think the general consensus on best practice is to do it this way:

MyClass = function (name, parent) {
this.name = name;
this.parent = parent;
}

MyClass.prototype.killMe = function () {
delete this.parent[this.name];
}

var thisClass = new MyClass("thisClass", this);
thisClass.killMe();
However, this is tricky business and I shy away from deleting instances within themselves if possible. I pretty much just use this.parent as a habit now because you never know when knowing the parent would be handy. I use this.name often enough (and now that I know setInterval can be invoked in an object's scope, I may not even need that anymore), but we could probably do without this.parent for now.

retrotron
06-05-2003, 10:50 PM
Finally, for subquark's question. I think I understand you now. Unfortunately, if you uncheck the "export in first frame", you have to do it in a workaround fashion. See this article: http://octaneinteractive.com/articles/preload/section1.html

You can use a symbol, component, or scripted preloader with this method, but all would probably follow the same approach.

sneeuwitje
06-05-2003, 11:52 PM
hi retrotron

Hope you're right. But i've come across these reference-in-reference's more lately, and sometime later the debugger would then crash Flash when things got bigger.:(

Still: I never succeeded in getting to the bottom of that problem, always found a work-around or kept it that way aslong as the movie tested true on-line. [dumb :D ]

I spent some time trying to trace myLoader.parent.myLoader[.parent.myLoader...] but can't get it to work

need to hit the bunk now
l8r

retrotron
06-06-2003, 12:24 AM
If I'm right, then this wouldn't work:

trace myLoader.parent.myLoader[.parent.myLoader...]

It only goes to myLoader.parent.

Cool.

CyanBlue
06-07-2003, 12:42 AM
Huh... That's strange...

I got rid of the setInterval and used onEnterFrame instead, and now that pause between changint the window is gone... Strange... Hm...

retrotron
06-07-2003, 12:44 AM
hmmm....so it runs nice and smooth now?

CyanBlue
06-07-2003, 12:59 AM
This one has no duplicate on the Flash screen or ghost or whatever you call it... Oh, I am not saying there is none like yours, but it got whole lot less... Smoothly??? I suppose...

http://www.cfhosting.it/CyanBlue/Tests/Preloader/Preloader05.html
http://www.cfhosting.it/CyanBlue/Tests/Preloader/Preloader05.zip

Still tingering with it though... ;)

What do you think???

retrotron
06-07-2003, 01:39 AM
You're saying this one is less smooth than preloader03?

CyanBlue
06-07-2003, 02:26 AM
That's what I thought... Why??? It's not??? :(

BTW, did some googling and added a CF counter... :)

retrotron
06-07-2003, 04:55 AM
For me, preloader5 is jerkier than preloader3. Is this the case for you?

A CF counter? With ColdFusion? Is that your first CF code?

CyanBlue
06-07-2003, 05:22 AM
Jerkier??? Hm... Totally opposite to what I see... :D

Arg... I got myself into the worse trouble... :(

Stuck at the worse one... Check this thread if you have time...
http://www.actionscript.org/forums/showthread.php3?s=&threadid=29118

Now, I got two instances of the preloader on the stage, but I have no way of displaying the progress into the text field... :(

I guess I'll have to go back to setInterval() because of this problem anyways... Arg...

subquark
06-07-2003, 02:12 PM
thanks for the link Retrotron, THAT is what I was looking for. I'll have to try it out, I find that once you drag a component onto the stage, it really loads that very first frame, regardless of the export being checked or not (albeit, there is a difference, but not to the extent indicated in the link you posted). ciao for now . . . :)

retrotron
06-07-2003, 04:15 PM
Okay, now that CyanBlue gets his wrapped up, I run into a preloader problem, or maybe it's just a curiosity.

I have this a movieclip method called "dataPreloader". It simply creates a simple graphic that displays a loading bar and the number of bytes loaded. I'm using it here to display how much of an XML document has loaded.

If you follow what the trace output is doing, it gives "undefined" for a while, then "0", then the bytes.

Why does it give me undefined at first? If there's no XML object, it should give me undefined, but there is one, so it should just give me "0" or bytesLoaded. Where is the "undefined" coming in . . . ?


// dataPreloader -----------------------------------------------------------//

MovieClip.prototype.dataPreloader = function(target, props) {
// initialize variables
this.target = target;
(props == undefined) ? this.props = new Object(): this.props = props;
if (props.position == undefined) { this.props.position = {x: 10, y: 10}; }

// draw loader line
this.createEmptyMovieClip("line_mc", (this.getDepth() + 1));
with (this.line_mc) {
lineStyle(1, 0x676767);
moveTo(0, 0);
lineTo(147, 0);
_xScale = 5;
} // end "with (this.line_mc)"

// set TextFormat
preloaderTF = new TextFormat();
preloaderTF.color = 0x676767;
preloaderTF.font = "arial";
preloaderTF.size = 11;

// create textfields
this.createTextField("loading_txt", (this.getDepth() + 2), 0, 1, 150, 30);
with (this.loading_txt) {
html = true;
htmltext = "loaded:";
setTextFormat(preloaderTF);
} // end "with (this.loading_txt)"
this.createTextField("loaded_txt", (this.getDepth() + 3), 40, 1, 110, 30);
preloaderTF.align = "right";

// onEnterFrame() which checks and updates bytesLoaded
this.onEnterFrame = function() {
trace(this.target.getBytesLoaded());
this.line_mc._xscale = (this.target.getBytesTotal()/this.target.getBytesLoaded()) * 100;
with (this.loaded_txt) {
html = true;
htmltext = this.target.getBytesLoaded() + "bytes";
setTextFormat(preloaderTF);
} // end "with (this.loaded_txt)"
} // end onEnterFrame
} // end dataPreloader() method

// end dataPreloader -----------------------------------------------------//

// InitIssue class ---------------------------------------------------------//

_global.InitIssue = function() {
this.getDocument();
} // end InitIssue() constructor

InitIssue.prototype.getDocument = function() {
this.docXML = new XML();
this.docXML.ignoreWhite = true;
this.docXML.parent = this;
this.docXML.onLoad = this.swonkDocument;
this.docXML.load("http://www.w3.org/TR/2000/REC-xml-20001006.xml");
this.docPreloader = _root.createEmptyMovieClip("docPreloader_mc", 1000010);
this.docPreloader.dataPreloader(this.docXML);
} // end getDocument() method

InitIssue.prototype.swonkDocument = function(success) {
// make sure xml has loaded
if (success) {
// this.parent.docPreloader.removeMovieClip();
this.parent.setDocument();
} else {
displayError("<b>Error: an XML document failed to load properly</b>");
} // end "if (success)"
} // end swonkDocument() method

// end InitIssue class ----------------------------------------------------//

var thisIssue = new InitIssue();

CyanBlue
06-07-2003, 04:31 PM
Nice... :)

Drawing in the beginning is abit weird though... It draws first to the left off to the screen, and to the right off to the screen, and then works normally...

As for the numbers... I get this result... I do not get undefined, however, it doesn't stop when the data reaches 201918...0
1093
9853
14233
21533
30293
31753
36133
44893
46353
55113
56573
59493
68253
75553
84313
85773
90153
98913
106213
114973
120813
129573
131033
135413
144173
145633
151473
160233
161693
166073
174833
176293
180673
189433
190893
195273
201918I gotta go out with my brother-in-law for a while... Will go out to the D&B or something... Will be back... :)

retrotron
06-07-2003, 04:31 PM
Blast, now I'm not getting an "undefined" (which is correct, it shouldn't be showing "undefined") . . . but I haven't changed anything. The mysteries . . .

retrotron
06-07-2003, 04:41 PM
Ah, thanks for the output CyanBlue, I'm getting the same thing now too. Weird.

The drawing is weird because I had a tiny mistake. ;) The line that sets the _xscale should be this:

this.line_mc._xscale = (this.target.getBytesLoaded()/this.target.getBytesTotal()) * 100;


Have fun with the brother-in-law!

retrotron
06-07-2003, 05:09 PM
Okay, another problem. When I send a parameter with x and y coordinates for the loader, the loader gets drawn before the x and y coordinates get set, even though the code sets _x and _y before the loader gets drawn. Why don't the _x and _y properties get set first? If there's a precedence thing here, then how to I force the _x and _y values to get set first?

Here's the modified code:


// dataPreloader -----------------------------------------------------------//

MovieClip.prototype.dataPreloader = function(target, pos) {
// initialize variables
this.target = target;
(pos == undefined) ? this.pos = {x: 100, y: 100}: this.pos = pos;

// position clip
this._x = this.pos.x;
this._y = this.pos.y;

// draw loader line
this.createEmptyMovieClip("line_mc", (this.getDepth() + 1));
with (this.line_mc) {
lineStyle(1, 0x676767);
moveTo(0, 0);
lineTo(147, 0);
_xScale = 5;
} // end "with (this.line_mc)"

// set TextFormat
preloaderTF = new TextFormat();
preloaderTF.color = 0x676767;
preloaderTF.font = "arial";
preloaderTF.size = 11;

// create textfields
this.createTextField("loading_txt", (this.getDepth() + 2), 0, 1, 150, 30);
with (this.loading_txt) {
html = true;
htmltext = "loaded:";
setTextFormat(preloaderTF);
} // end "with (this.loading_txt)"
this.createTextField("loaded_txt", (this.getDepth() + 3), 40, 1, 110, 30);
preloaderTF.align = "right";

// onEnterFrame() which checks and updates bytesLoaded
this.onEnterFrame = function() {
trace(this.target.getBytesLoaded());
this.line_mc._xscale = (this.target.getBytesLoaded()/this.target.getBytesTotal()) * 100;
with (this.loaded_txt) {
html = true;
htmltext = this.target.getBytesLoaded() + "bytes";
setTextFormat(preloaderTF);
} // end "with (this.loaded_txt)"
} // end onEnterFrame
} // end dataPreloader() method

// end dataPreloader -----------------------------------------------------//


// InitIssue class ---------------------------------------------------------//

_global.InitIssue = function() {
this.getDocument();
} // end InitIssue() constructor

InitIssue.prototype.getDocument = function() {
this.docXML = new XML();
this.docXML.ignoreWhite = true;
this.docXML.parent = this;
this.docXML.onLoad = this.swonkDocument;
this.docXML.load("http://www.w3.org/TR/2000/REC-xml-20001006.xml");
this.docPreloader = _root.createEmptyMovieClip("docPreloader_mc", 1000010);
this.docPreloader.dataPreloader(this.docXML, {x: 200, y: 200});
} // end getDocument() method

InitIssue.prototype.swonkDocument = function(success) {
// make sure xml has loaded
if (success) {
// this.parent.docPreloader.removeMovieClip();
this.parent.setDocument();
} else {
displayError("<b>Error: an XML document failed to load properly</b>");
} // end "if (success)"
} // end swonkDocument() method

// end InitIssue class ----------------------------------------------------//

var thisIssue = new InitIssue();

CyanBlue
06-07-2003, 05:10 PM
You need something like this sort of if routine or whatever it is to check if the loading is done... ;)

if (this.target.getBytesLoaded() <= this.target.getBytesTotal())

Gotta go... ;)

retrotron
06-07-2003, 05:33 PM
Have fun, when you get back here's a question for you (or whoever else sees my problem):

I'm not sure why I need what you suggested (the if statement), can you explain?

So here's the problem. I'm trying to place an empty clip at _x = 200, _y = 200. Then I want it to draw the preloader, then start executing the onEnterFrame. But what happens is the clip is first drawn at 0, 0 and then the _x and _y gets set.

However, the code which sets the _x/_y occurs before anything at all is drawn, and before the onEnterFrame . . . in fact, if you try and set _x and _y before the dataPreloader() method is called, it still does the same thing, e.g.

// inside the InitIssue.prototype.getDocument() method:

this.docPreloader = _root.createEmptyMovieClip("docPreloader_mc", 1000010);
this.docPreloader._x = 200;
this.docPreloader._y = 200;
this.docPreloader.dataPreloader(this.docXML, {x: 200, y: 200});
// it still first draws the clip at 0, 0 and then moves it to 200, 200

The code I placed above is a dummy test. The attachment contains the real code I'm using, and it consistently draws at 0, 0 and then moves to 200, 200. I need it to draw at 200, 200. :(

retrotron
06-07-2003, 08:01 PM
Okay, I must be retarded. Stupid mistake.

In the real code (the attachment above), there were two preloaders. I thought I had commented the first one out, so I didn't change its _x/_y properties, I was only messing with the second preloaders _x/_y properties. Well, I just realized that I hadn't actually commented out the first one, so it was drawing at the default 0, 0 (like it should be), then the second preloader was being drawn at the new _x/_y coordinates. So it was working all along. Heh heh (nervous laugh), Saturday laziness I guess.

As for the code I pasted in a few posts back (which is slightly different from the attachment), that seems to be working too . . .

So all's fixed now. :)

CyanBlue
06-07-2003, 10:18 PM
Oh, don't worry too much about it... Things happen... :)

Let me tell you one funny(?) story of mine...

I was working on the preloader the other day, and I was trying to apply a new text format to the percentage and progress strings... Heck... I've been messing with it for almost three hours, and I had no way of finding out what the heck is wrong with the code, and the AS.org was down...
Dang... I needed some rest, so I went to watch some TV for a couple hours, and went back to the computer for a couple more hours... And I finally found the BUG!!!

loaderTF = new TextField();

Get it??? I have set it to the TextField() not TextFormat() and I have wasted good six hours just because of that... :D

Things happne... ;)

retrotron
06-07-2003, 11:14 PM
Hee hee, the stupid things us actionscripters do.

CyanBlue
06-07-2003, 11:20 PM
Yup... Things happen all the time... ;)

I was thinking maybe we could make a one preloader that does all the preloading like JPEG, SWF, MP3, XML or whatever it is... What do you think??? One preloader does all the work or individual preloaders for each cases???

retrotron
06-08-2003, 12:07 AM
Yeah, an all purpose preloader would be fun . . . it's been done plenty of times before, but then again, we pretty much sit around and reinvent the wheel here. ;)

As for the best approach, I'll have to think about that . . . we could have at least two types: data (text, loadvars, xml) and image/swf. Then there'd be two different approaches: a component that one could attach at authoring time, or a class/prototype that would be generated at runtime (no symbols) . . . so many options . . . what are you thinking?

Well I must go be a security guard and pretend like I'm a ninja for the rest of the weekend, I'll be back online tomorrow. Adieu.

CyanBlue
06-08-2003, 12:12 AM
Huh... Security guarding again??? Be safe out there... ;)

Wonder where you work... You gotta let me know so that I won't bust that place... :p

Well... All purpose preloader... More concern I have is the excessive codes that does not apply to the specific occasions... Say that I have a preloader that load all kinds of things... and then I mush have at least two or three different routines for specific data type, right??? So, if I use JPEG loading, then the amount of the code that goes with the XML loading will just be there to take up the memory or not??? It it eats up the memory while it is doing nothing, then there is no reason for doing it, I think... What do you think??? ;)

retrotron
06-08-2003, 12:18 AM
It's just a high school . . . I pretty much get paid to sit and read philosophy. :)

Yeah, multiple preloaders for multiple occassions, a kind of "preloader" toolbox or something.

Okay, I'm out of here.

CyanBlue
06-08-2003, 12:33 AM
A high school??? :)

Yup... go get some reading done... Talk to you later...

Gerebeto
09-18-2003, 08:29 PM
Hello,
´
i was checking your class and i have something that might interest you: http://proto.layer51.com/d.aspx?f=661

However i am having some problems to apply it?

Can u give me a hand?

Imagine u want to load a file and display the percentage loaded, how would u do?

I am asking, as i am having some problems in making it work and it's something similar to your class but going a little bit further...i think.

Thanks,
Miguel

sneeuwitje
09-19-2003, 07:47 AM
see you've been asking @ proto.layer51.com aswell, maybe best wait for an answer, though it might never come as the example you ask for is right below ... see it doesn't work out of the box aswell, i'll try to do diggin' and figure out why ... be patient and let me know if answer comes from layer51 ;)

sneeuwitje
09-19-2003, 10:21 AM
Don't know what's wrong with that script, but did get it to work (http://antenna-men.xs4all.nl/flash_preloader_test/index.html) in the attached file. Only works on-line though !! (prob cuzzof the ASbroadcaster bit i don't understand.)

there's 4 dollar-signs($) in the class, that leads me to think this script originates from php-code, maybe that's the trouble, though leaving them out makes no diff to me.

it also a preloader that i use alot myself these days, that is much more straightforward, but atleast this file offers a start for troubleshooting the proto.layer51 preloader.

hope this helps a bit

PS: for futher developments on proto.layer51 preloader by cdMan go there (http://proto.layer51.com/d.aspx?f=661)

Gerebeto
09-19-2003, 11:27 AM
Thanks for your help.

If i get any answer i will let u know.

Cheers,
Miguel

retrotron
09-19-2003, 04:18 PM
Haven't had time to work through the class myself yet, but the dollar signs ($) are just a convention recommended by Branden Hall and Samuel Wan in their OOP book that many have taken up in their practice. They suggest using the dollar signs to indicate variables as a convention because it's clearer that way, especially since other languages such as php use dollar signs. So yeah, leaving them out doesn't matter. ;)

sneeuwitje
09-19-2003, 08:06 PM
yeah, well it thought $-signs was like numbers ... never at the 1st index of a variable name, or you head for trouble ... apparently that changed with AS going OOP (true ...?), or numbers are in no way comparable with their 'capitals' when it comes to using them in programming languages ... there's quite a lot that have special meaning in various languages though ... can you give us more insight retrotron?

btw: i worked out a WORKING one-frame version of the proto.layer51 preloader (by cdMan) that I posted overthere (http://proto.layer51.com/d.aspx?f=661#c1505) where it belongs :)

happy preloading! (while flash7 is still uncommon ...)

retrotron
09-20-2003, 01:09 AM
In AS, the dollar sign is treated like a string character, no different in AS's mind than any other letter (i.e. it's not a reserved character/symbol). But in other languages (such as PHP), the dollar sign is a reserved character that designates that the following word is a variable name.

It should probably also be said that not all the characters you get with SHIFT + number are unreserved. The percent symbol, for example, is ECMA's reserved character for "mod", while the asterisk is ECMA's reserved character for "multipy". So here it just happens to be the case that the dollar sign is not a reserved ECMA character and can be used as a string.

So yeah, I wouldn't go using dollar signs in other languages until you know if the dollar sign is a reserved character. In the case of AS, it's not, so using a dollar sign is just a convention that some programmers use to make their variables more easily identifiable. One could just as easily accomplish the same effect by beginning all variables with an x or z or q or some other odd character.

Nice work on the preloader sneeuwitje, I look forward to getting a few moments to work through the code, especially since I don't have MX2004 yet. ;)

CyanBlue
01-20-2004, 12:16 AM
Somebody wanted the file from the previous post and this is what I have from that page...

seanlail
06-20-2006, 12:42 PM
I have a preloader in which it prelaods the content.
I need to add the xml preloading into it.
I have 5 xml files that I need to be preloaded so that it doesnt have to load seperately later in the movieclip.

My preloader is currently like this:

A movieclip, with 1st frame stopping the root from playing:

2nd frame:

kBytesLoaded = _parent.getBytesLoaded()/1024;
kBytesTotal = _parent.getBytesTotal()/1024;
kBytesRemaining - kBytesTotal - kBytesLoaded;

percentLoaded = 100 * kBytesLoaded / kBytesTotal;
percentRemaining = 100 - percentLoaded;
loadBar._xScale = percentLoaded;


3rd frame:

if (percentLoaded < 99){
gotoAndPlay(2);

} else {

_parent.play();
stop();
}


This is how I'm loading the XML that goes into a scrollpane.
When a certain button is clicked, the content will display a menu, that uses 1 of the 5 xml files for data.


var yPos = -15;
var depthCount = 1;
var dataXML = new XML();
dataXML.ignoreWhite = true;
dataXML.load("file1.xml");
//dataXML.load("file1.xml?" + regionQ + "");
dataXML.onLoad = checkLoading;

function checkLoading(success) {
if (success == true) {
//_parent.theScrollPane.invalidate();
var rootNode = dataXML.firstChild;
var total = rootNode.childNodes.length;

//Load the links Text
var tLink = rootNode.firstChild;
for (i=0;i<total;i++) {
createLink("tLink" + i, tLink);
var totalInner = tLink.childNodes.length;
var tnLink = tLink.firstChild;
for (j=0;j<totalInner; j++){
createLink("tnLink" + j + ""+ i, tnLink);
tnLink = tnLink.nextSibling;
}
tLink = tLink.nextSibling;
}
}
}

function createLink(newObj, aNode){
duplicateMovieClip(this.step1, newObj, depthCount++);
var tcl = eval(newObj);
tcl.aLink = aNode.attributes.region_link;
yPos +=16

setName(tcl, aNode.attributes.region_name, 1);
tcl._x = 11;
tcl._y = yPos;
_parent.theScrollPane.invalidate();

}

function setName(obj, theName, Size){
obj._height = obj._height*Size;
obj._width = obj._width*Size;
obj.BoxName.text = theName;
_parent.theScrollPane.invalidate();
}


The scrollpane is looking for the identifyer of the xmlloader mc and then uses that content.

So... I need the preloader to load the flash swf and the xml and show total preloading of that... is this possible???

Doccie
10-22-2006, 12:59 PM
Mkay, old thread but I am dealing with something similar at the moment and was really interested in this idea.

I was thinking of going at it with a while loop and an array of the files that need loading. So I would have an array with

loadElements = new Array("newDoc.xml", "image.jpg", "movie.swf");

and than a while loop to check if the array is empty or not. If it's not and the last element has stopped loading you just take out the first element from the array, check it's extension and either load the appropriate .as file or just define some functions in the .fla itself.

The question remains if this would be straineous on the preloader or not. I will try and write some code to get this working, but I am by no means an expert :)