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?
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.
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);
this.gotoAndStop("begin") doesn't make sense. "this" would refer to ch, but ch has been removed.
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 { .
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]); }
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?
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 } }
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 && loaded [quoted text, click to view] >0){ clearInterval(preloadI); . . . // yada yada yada if dynamically created
movie clips have a kb value (and I do not think that they do), then, obviously, the '0' number should be higher. td
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]); }
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?
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?
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.
Don't see what you're looking for? Try a search.
|