Groups | Blog | Home
all groups > flash actionscript > february 2005 >

flash actionscript : prealoader problem


SDALW
2/25/2005 6:52:42 PM
My goal is to load all of the .swf movies prior to the main movie beginning. I
am using the following code - which is posted in multiple places. BTW - whoever
wrote it - thank you. The problem is: Trace shows that the movies are
loading correctly, but the start of the movie ('begin') is supposed to start
ONLY after all the movies are loaded. For some reason - it goes there in the
middle of the loading. If I put stop (); at the beginning - it never goes to
('begin'); Here is the code: contArr = [ 'CLIP1.swf', 'CLIP2.swf',
'CLIP3.swf', 'CLIP4.swf', 'CLIP5.swf', 'CLIP6.swf', 'CLIP7.swf', 'CLIP8.swf',
'CLIP9.swf', 'CLIP10.swf', 'CLIP11.swf', 'CLIP12.swf', 'CLIP13.swf',
'CLIP14.swf', 'CLIP15.swf', 'CLIP16.swf', 'CLIP17.swf', 'CLIP18.swf',
'CLIP20.swf', 'CLIP21.swf']; var nr nr = 0; function preloadClips (nr) { var
cnt = this.createEmptyMovieClip('container',10); cnt._visible = false; var ch =
this.createEmptyMovieClip('check',11); ch.onEnterFrame = function () { var bl =
this._parent.container.getBytesLoaded(); var bt =
this._parent.container.getBytesTotal(); if (bl/bt==1) { trace ('loaded ' +
contArr[nr]); this.removeMovieClip(); this._parent.container.removeMovieClip();
trace (nr); if (this.nr<=contArr.length) { preloadClips(++nr); } else {
return; gotoAndPlay ('begin'); } } } cnt.loadMovie(contArr[nr]); }
preloadClips(0); I've tried substituting this - and it still doesn't work: if
(this.nr==contArr.length) { gotoAndPlay ('begin'); } else if { (this.nr
<=contArr.length) { preloadClips(++nr); } else { return; Any suggestions?

kglad
2/26/2005 6:13:44 AM
change this:

if (this.nr<=contArr.length) {
preloadClips(++nr);
}

to:

nr++;
if (nr<contArr.length) {
preloadClips(nr);
}

p.s. remove that return statement which serves no purpose execept to prevent
your gotoAndPlay() statement from executing.
SDALW
2/26/2005 11:07:55 PM
Okay - I must be doing something wrong. I added the stop - because if I don't
- it automatically goes to 'begin'. But - it still doesn't go to begin - even
after it is preloaded. 2nd question - is there anyway to add a percentage - or
dynamic text to tell that ___% is loaded? stop(); contArr = [ 'CLIP1.swf',
'CLIP2.swf', 'CLIP3.swf', 'CLIP4.swf', 'CLIP5.swf', 'CLIP6.swf', 'CLIP7.swf',
'CLIP8.swf', 'CLIP9.swf', 'CLIP10.swf', 'CLIP11.swf', 'CLIP12.swf',
'CLIP13.swf', 'CLIP14.swf', 'CLIP15.swf', 'CLIP16.swf', 'CLIP17.swf',
'CLIP18.swf', 'CLIP20.swf', 'CLIP21.swf']; var nr; nr = 1; function
preloadClips (nr) { var cnt = this.createEmptyMovieClip('container',10);
cnt._visible = false; var ch = this.createEmptyMovieClip('check',11);
ch.onEnterFrame = function () { var bl =
this._parent.container.getBytesLoaded(); var bt =
this._parent.container.getBytesTotal(); if (bl/bt==1) { trace ('loaded ' +
contArr[nr]); this.removeMovieClip();
this._parent.container.removeMovieClip(); trace (nr); nr++; if
(nr<contArr.length) { preloadClips(nr); } else { this.gotoAndStop
('begin'); } } } cnt.loadMovie(contArr[nr]); } preloadClips(0);
kglad
2/27/2005 2:15:52 AM
this.gotoAndStop("begin") doesn't make sense. "this" would refer to ch, but ch has been removed.

SDALW
2/28/2005 12:17:34 AM
I changed the script as you directed: _root._parent.gotoAndStop ('begin'); as
I am running this from another .swf. Then I put a trace below else {
_root._parent.gotoAndStop ('begin'); trace ('hello'); I don't see anything -
which tells me that it isn't getting past else { .
SDALW
2/28/2005 1:41:53 AM
Okay - I finally got it to go to ('begin') and trace ('hello'). But - the last
movie it loaded is showing on the screen. Didn't it unload the movie clip?
Also - any ideas or places you could direct me for ideas on a preloader for the
multiple movies? I've tried a percentage - but DUH that doesn't work.
Here's the script I've got - the last movie loaded shows on the screen
('begin'); stop(); contArr = [ 'CLIP1.swf', 'CLIP2.swf', 'CLIP3.swf',
'CLIP4.swf', 'CLIP5.swf', 'CLIP6.swf', 'CLIP7.swf', 'CLIP8.swf', 'CLIP9.swf',
'CLIP10.swf', 'CLIP11.swf', 'CLIP12.swf', 'CLIP13.swf', 'CLIP14.swf',
'CLIP15.swf', 'CLIP16.swf', 'CLIP17.swf', 'CLIP18.swf', 'CLIP20.swf',
'CLIP21.swf']; var nr; nr = 1; function preloadClips (nr) { var cnt =
this.createEmptyMovieClip('container',10); cnt._visible = false; var ch =
this.createEmptyMovieClip('check',11); ch.onEnterFrame = function () { var bl =
this._parent.container.getBytesLoaded(); var bt =
this._parent.container.getBytesTotal(); if (bl/bt==1) { trace ('loaded ' +
contArr[nr]); this.removeMovieClip(); this._parent.container.removeMovieClip();
trace (nr); nr++; if (nr<contArr.length) { preloadClips(nr); } else {
_root.gotoAndStop ('begin'); trace ('hello'); } } }
cnt.loadMovie(contArr[nr]); }
SDALW
2/28/2005 2:20:04 AM
I added unloadMovie('_root.container'); to the script and it worked great.
else { unloadMovie('_root.container'); _root.gotoAndStop ('begin'); trace
('hello'); Now... my other problem - and this is going to seem so simple to
you... I'm loading this movie within another movie. Therefore I would assume
that I would change the script to _root._parent.gotoAndStoop ('begin'); But
it doesn't go to ('begin') when I play it from the root movie. If I play it in
the Flash preview - it does. Would someone point out what I'm not seeing?
Please?
kglad
2/28/2005 2:55:37 AM
i think it would be cleaner to redo this coding especially if you want to
display the load progress of that family of swfs:

for(ivar=1;ivar<=21;ivar++){
rclip=this.createEmptyMovieClip("container"+ivar,ivar);
rclip.loadMovie("CLIP"+ivar+".swf");
}
preloadI=setInterval(preloadF,100);
function preloadF(){
total=0;
loaded=0;
for(ivar=1;ivar<=21;ivar++){
loaded += this["container"+ivar].getBytesLoaded();
total += this["container"+ivar].getBytesTotal();
}
percent = Math.round(100*loaded/total);
if(percent==100){
clearInterval(preloadI);
this.gotoAndStop("begin"); // assuming "begin" is on the same timeline that
contains this code
}
}
toddde
2/28/2005 4:44:56 PM
I agree with kglad about creating a container clip for each movie you want to
load. Also, I liked the innovative way in which he creates master 'loaded' and
'total' variables. I am not sure if dynamically created empty movie clips have
any kb value. I do not think that they do, because they are created on the
user's platform. Therefore, there is nothing to load. Empty movie clips,
however, that are created at author time - I think - have 10 kbs. In any
event, assuming that dynamically created movie clips do not have a kb value
greater than 0, you might want to add 'if (percent == 100 &amp;&amp; loaded
[quoted text, click to view]
movie clips have a kb value (and I do not think that they do), then, obviously,
the '0' number should be higher. td
SDALW
3/1/2005 12:25:57 AM
This totally confused me even more - sorry. I have a main movie (Login.swf) and
call this movie (Entry.swf) by this button action. on (release) {
unloadMovie('_root.parent'); loadMovie('Entry.swf', '_root.Entry_mc'); }
The Entry.swf is the timeline that I run multiple movies off of to preload. If
I use the original script that we worked on - which I need to, since the movies
are actually not conveniently named Clip1, Clip2...etc. But have different
names and would be difficult to rename) : The following script works great in
the Entry.swf either TEsted within Flash or standalone. However, If I click the
button in Login.swf - I don't see anything. The movie doesn't move to 'begin' -
and I don't know if it preloaded the movies in the array. I know it is only a
matter of paths - but I have tried everything and can't figure it out. I'm
frustrated - as it is so close.... yet not quite there. Since the other paths
in the script are relative - they don't need to be renamed - correct? And I
know the button path is correct - as it works without the preloader script. So
- it has to be something in the following script - pathwise. HELP please?
stop(); contArr = [ 'CLIP1.swf', 'CLIP2.swf', 'CLIP3.swf', 'CLIP4.swf',
'CLIP5.swf', 'CLIP6.swf', 'CLIP7.swf', 'CLIP8.swf', 'CLIP9.swf', 'CLIP10.swf',
'CLIP11.swf', 'CLIP12.swf', 'CLIP13.swf', 'CLIP14.swf', 'CLIP15.swf',
'CLIP16.swf', 'CLIP17.swf', 'CLIP18.swf', 'CLIP20.swf', 'CLIP21.swf']; var nr;
nr = 1; function preloadClips (nr) { var cnt =
this.createEmptyMovieClip('container',10); cnt._visible = false; var ch =
this.createEmptyMovieClip('check',11); ch.onEnterFrame = function () { var bl =
this._parent.container.getBytesLoaded(); var bt =
this._parent.container.getBytesTotal(); if (bl/bt==1) { trace ('loaded ' +
contArr[nr]); this.removeMovieClip(); this._parent.container.removeMovieClip();
trace (nr); nr++; if (nr<contArr.length) { preloadClips(nr); } else {
unloadMovie('_root.container'); _root.gotoAndStop ('begin'); trace ('hello'); }
} } cnt.loadMovie(contArr[nr]); }
SDALW
3/1/2005 5:03:54 PM
SDALW
3/1/2005 5:04:02 PM
kglad
3/2/2005 3:21:33 AM
try

SDALW
3/2/2005 3:31:18 AM
I can't tell if that will work or not - as the preloader won't work at all.
I've got the movie to load, but it just stops and the % stays at 0. For some
reason the preloader script isn't running. When I play the .swf by itself, it
works great. But when I call if from Login.swf, it won't run at all. Is this a
path problem?
SDALW
3/2/2005 3:52:26 AM
I think that I need to replace all of the this. script with
_root.EntryScreen_mc. I did that, but then come to the script that has
this._parent in it. Would I replace it with _root.EntryScreen_mc._parent ? I
did that and it doesn't run. Seems to me that it has to be something else than
_parent. Suggestions?
kglad
3/2/2005 3:27:01 PM
SDALW
3/3/2005 6:58:21 AM
Yes - that worked perfectly. I am now going to try to use the other script you
offered. I really needed to figure this one out first - as it was working/ then
not. You have been so helpful - and patient. I really appreciate it. I do have
to say that I've been learning Flash for the past 1.5 years and you - and this
forum have always, always helped me when I'm in a tough spot. It's crazy that
it makes me lose sleep though. Kind of like a puzzle you can't figure out.
Thanks again.
kglad
3/3/2005 3:46:41 PM
AddThis Social Bookmark Button