Preloaded pics not fully loaded  
Author Message
DKnighte





PostPosted: 2004-11-6 6:13:37 Top

flash-actionscript, Preloaded pics not fully loaded PROBLEM: I want to load 9 pics and once they are loaded I want the animation to
start. The animation is a simple swipe off the movie clips containing the pics
across the stage. While the pics are loading, there is a simple 'Loading...'
move clip playing. This seems to work ok when I 'view as streaming' in Flash,
but when I view online the images don't seem to be loaded before the animation
starts. See at: www.simongroup.biz. Click 'Services'. Under the list of
services, click 'billboards/signs.' This is even more apparent when viewed at
56K dial up or lower. FILE CONSTRUCTION: First Frame is the 'Loading...' clip.
Second Frame is the 'Loading' clip and the adHolder move clips that the images
load into. The code for this frame includes the pics being loaded into the
adHolder clips using the loadMovie as well as: onEnterFrame=function(){
Loaded=adHolder1.getBytesLoaded()+adHolder2.getBytesLoaded()+adHolder3.getBytesL
oaded()+adHolder4.ol_one.getBytesLoaded()+adHolder5.mk_3d.getBytesLoaded()+adHol
der6.mk_future.getBytesLoaded()+adHolder7.bi_buildings.getBytesLoaded()+adHolder
8.getBytesLoaded()+adHolder9.getBytesLoaded();
Total=adHolder1.getBytesTotal()+adHolder2.getBytesTotal()+adHolder3.getBytesTota
l()+adHolder4.ol_one.getBytesTotal()+adHolder5.mk_3d.getBytesTotal()+adHolder6.m
k_future.getBytesTotal()+adHolder7.bi_buildings.getBytesTotal()+adHolder8.getByt
esTotal()+adHolder9.getBytesTotal(); percent=Math.round((Loaded/Total)*100);
if(percent>=100){ gotoAndPlay('start'); } } Note: Some of the pics have a
shadow. The shadow is in the adHolder clip so that it swipes with the pic
during the animation. That's why some of the pics are loaded into a clip inside
the adHolder Clip. So anyone know what's going on here?

 
Rothrock





PostPosted: 2004-11-7 3:56:00 Top

flash-actionscript >> Preloaded pics not fully loaded Sorry, but your post is almost impossible to read. If you are using the web
forums, use the attach code button to paste your actionscript into your
message. On a more practical note, I have found that trying to load a bunch of
pictures at once kinda 'chokes' flash and some of them will be forgotten.
Instead I have found that loading them serially is a better strategy. (At least
for me.)Also if you are using MX04, I recommend the MovieClipLoader class.

 
DKnighte





PostPosted: 2004-11-9 0:16:00 Top

flash-actionscript >> Preloaded pics not fully loaded OK. I've reentered my question. Used to be able to write the question just in
the box with code and all but not anymore I guess. Man, I even previewed it
before I sent it out. Anyway, thanks for pointing it out Rothrock. By the way,
want do you mean by loading them 'serially.' Should also mention, I'm using
plain ol' MX, not MX 2004. PROBLEM: I want to load 9 pics and once they are
loaded I want the animation to start. The animation is a simple swipe off the
movie clips containing the pics across the stage. While the pics are loading,
there is a simple 'Loading...' move clip playing. This seems to work ok when I
'view as streaming' in Flash, but when I view online, the images don't seem to
be loaded before the animation starts. See at: www.simongroup.biz. Click
'Services'. Under the list of services, click 'billboards/signs.' This is even
more apparent when viewed at 56K dial up or lower. FILE CONSTRUCTION: First
Frame is the 'Loading...' clip. Second Frame is the 'Loading' clip and the
adHolder movie clips that the images load into. The code for this frame
includes the pics being loaded into the adHolder clips using the loadMovie as
well as the attached code below. Note: Some of the pics have a shadow. The
shadow is in the adHolder clip so that it swipes with the pic during the
animation. That's why some of the pics are loaded into a clip inside the
adHolder Clip. So anyone know what's going on here?

onEnterFrame=function(){

Loaded=adHolder1.getBytesLoaded()+adHolder2.getBytesLoaded()+adHolder3.getBytesL
oaded()+adHolder4.ol_one.getBytesLoaded()+adHolder5.mk_3d.getBytesLoaded()+adHol
der6.mk_future.getBytesLoaded()+adHolder7.bi_buildings.getBytesLoaded()+adHolder
8.getBytesLoaded()+adHolder9.getBytesLoaded();

Total=adHolder1.getBytesTotal()+adHolder2.getBytesTotal()+adHolder3.getBytesTota
l()+adHolder4.ol_one.getBytesTotal()+adHolder5.mk_3d.getBytesTotal()+adHolder6.m
k_future.getBytesTotal()+adHolder7.bi_buildings.getBytesTotal()+adHolder8.getByt
esTotal()+adHolder9.getBytesTotal();
percent=Math.round((Loaded/Total)*100);
if(percent>=100){
gotoAndPlay("start");
}
}

 
 
Rothrock





PostPosted: 2004-11-9 0:30:00 Top

flash-actionscript >> Preloaded pics not fully loaded 'Serially' -- meaning one after the other. Make an Array of all the clips you
have to load. Use your loading script to start loading the first element from
the array. When it is loaded, in that if(percent>=100) part, have it check to
see if there is another element in the array, if there is, then start loading
that. Finally, when there aren't anymore in the array, you can do the
gotoAndPlay. If you are using some kind of percent bar, this will require a
different approach. Since you won't know the total bytes for all the files, you
will only know the length of the array. If most of the files in the array are
approximately the same length, then just show the percent of files loaded. Also
for this approach it will probably be easier if all your holders have the same
structure. So put the holder in a container movie. If they need a shadow have
that, but if they don't need it the shadow clip will just be empty.

 
 
DKnighte





PostPosted: 2004-11-9 0:45:00 Top

flash-actionscript >> Preloaded pics not fully loaded I will try that and let you know how it goes. Thank you for your help.
 
 
DKnighte





PostPosted: 2004-11-10 0:45:00 Top

flash-actionscript >> Preloaded pics not fully loaded Yes. One after other worked. Who knew you couldn't just jam everything through
at once? Thanks for your help. For those who come after me looking for answer
to the same problem, I've included my code. Don't profess it's the best or most
economical use of code, but it works.

bboardsArray = ["boater_billboard.jpg", "twins_billboards.jpg",
"molly_billboard.jpg", "ol_sign_one.jpg", "mk_sign_3d.jpg",
"mk_sign_future.jpg", "bi_sign_buildings.jpg", "rita_billboard.jpg",
"Linda_billboard.jpg"];

i = 1;
loadMovie(bboardsArray[0], "adHolder0.mc");
createEmptyMovieClip("blank2", 100);
blank2.onEnterFrame = function() {
Loaded = eval("adHolder"+i).mc.getBytesLoaded();
Total = eval("adHolder"+i).mc.getBytesTotal();
percent = (Loaded/Total)*100;
if (percent>=100) {
if (i<bboardsArray.length) {
loadMovie(bboardsArray[i], eval("adHolder"+i).mc);
i++;
} else {
gotoAndPlay("start");
blank2.removeMovieClip();
}
}
};

 
 
DKnighte





PostPosted: 2004-11-10 1:22:00 Top

flash-actionscript >> Preloaded pics not fully loaded Wait! I spoke too soon. I guess I must have not cleared my cache first. The
pics still are not on the screen before the animation starts. I think what may
be happening is that the image files are loaded so the movie goes to the next
frame, but the pics aren't showing up on the screen fast enough. Is this a
processing thing? Anyway around it? Anyone know what the heck is going on and
how I can fix it? Am I the only one stupid enough not to be able to figure out
how to do a simple loading movie?

 
 
Rothrock





PostPosted: 2004-11-10 1:27:00 Top

flash-actionscript >> Preloaded pics not fully loaded Looks good. Here are a few pointers. Put var in front of Loaded, Total, and
percent. Inside of the else I would do a this.onEnterFrame=null; I see that you
are removing the movieClip, but what if you needed to load some more or
something? Also personally I don't like eval so I would use the array notation.
(It will make you look fancy! :)) I might get this a bit wrong but you could do
it like this Loaded=this['adHolder'+i][mc].getBytesLoaded(); That might be the
wrong scope, so sometimes I have to try a couple of variations to make sure I
get the right one. Good luck.

 
 
DKnighte





PostPosted: 2004-11-10 3:29:00 Top

flash-actionscript >> Preloaded pics not fully loaded I will try those corrections. I know I have some bad habits. I lean pretty
heavily on eval and I don't have a set pattern for naming variables which will
get me in trouble some day. But beyond that, the images are still not on screen
before the animation starts. (You can see at: www.simongroup.biz. Click
'Services'. Under the list of services, click 'billboards/signs.') The above
suggestions won't help solve this problem, will they? Any idea what will? I'm
considering sticking the images in the .swf instead of externally loading the
images. Then setting up the file to start playing the animation once the entire
swf is finished loading. This might help but it seems painful to go back and
change everything especially since externally loading files seems to be the way
to go.

 
 
DKnighte





PostPosted: 2004-11-10 4:37:00 Top

flash-actionscript >> Preloaded pics not fully loaded Whoops! Found my mistake. The 'i' variable was starting a number ahead of the
movie clip that was being loaded. So I would be loading the 3rd image but the
code would be checking to see if the 4th movie clip was loaded. Well, of course
the movie clip was loaded because it's just a small placeholder. But, the image
wasn't loaded yet and that's why the animation was running befor the loading
occurred. Anyway, enough of my whining I'm done. Thanks for all your help
Rothrick. Below is the adjusted code. (Followed most of your suggestions but
wimped out on getting rid of the eval).

bboardsArray = ["boater_billboard.jpg", "twins_billboards.jpg",
"molly_billboard.jpg", "ol_sign_one.jpg", "mk_sign_3d.jpg",
"mk_sign_future.jpg", "bi_sign_buildings.jpg", "rita_billboard.jpg",
"Linda_billboard.jpg"];

i = 0;
loadMovie(bboardsArray[i], eval("adHolder" +i).mc);
createEmptyMovieClip("blank2", 100);
blank2.onEnterFrame = function() {
varLoaded = eval("adHolder"+i).mc.getBytesLoaded();
varTotal = eval("adHolder"+i).mc.getBytesTotal();
varPercent = (varLoaded/varTotal)*100;
if (varPercent>=100) {
i++;
if (i<bboardsArray.length) {
loadMovie(bboardsArray[i], eval("adHolder"+i).mc);
} else {
gotoAndPlay("start");
this.onEnterFrame=null;
}
}
};

 
 
Rothrock





PostPosted: 2004-11-10 4:58:00 Top

flash-actionscript >> Preloaded pics not fully loaded I meant var Loaded, not varLoaded. That makes it a local variable and helps
speed things up, clear up cases of scope confusion, and is generally neater.
You don't have to not use eval, I just find it clunky. Especially since you
can't use eval on the left hand side of an equals sign. So if you want to do
things like this['adholder'+i]._alpha = 20; you will eventually need to learn
it. Or spend two lines to code a temporary variable with the result of the eval
and then set the _alpha. Finally, make sure you check this on an actual server
before you deploy. (And clear the cache!)

 
 
DKnighte





PostPosted: 2004-11-10 6:47:00 Top

flash-actionscript >> Preloaded pics not fully loaded I've been testing plenty. In fact, when I went over and tested on the Mac I
found out this wasn't work. After some tooling around on the Internet found the
solution. Thought I'd put it down here for posterity. <br> <br> You need to
test to make sure Total is greater than zero. Otherwise a Mac will interpret
that (0/0)*100=100. Or something cooky like that. So the result was the images
weren't loading before the animation starts. So your code needs to be: if
(Total>0 && Percent>=100). <br> <br>Rothrock, I'll fix the var thing
and get better acquainted with 'this' and brackets. Though I do have to add
that you can have an eval statement on the left if you're referring to a movie
clip. So eval('adholder'+i')._alpha = 20; will work. I've done it a lot :o.
Where the problem occurs is if you're trying to do a variable. For example,
eval('text' +i)='hello world'; doesn't work and then you have to do
set('text'+i, 'hello world');. That's where it becomes tedious. Actually the
whole eval thing becomes tedious too.

 
 
Rothrock





PostPosted: 2004-11-10 23:10:00 Top

flash-actionscript >> Preloaded pics not fully loaded DKnighte -- well I live and learn! I guess when they dropped eval on the LHS for half of the things I used it for, I just sort of wrote it off in my head for anything.