I have several large movies (2-3 mb each) that are loaded at certain frames using 'loadMovieNum' and the preloader I have on the parent movie doesn't load these - which I guess makes sense - but I'm not sure what to do in order to get these to load before they get to the frame that loads / plays them. I'm a newbie and just not sure the most efficient way to do this and would appreciate an experts . . . well . . . expertise. The movies being loaded are several frames of a bitmap rendered animation (from Strata 3D). Ideas? Thanks in advance. Tim
Thanks for the reply. Here's the code for the third frame (fouth frame just has a 'gotoAndPlay (2);" loadedbytes = getBytesLoaded(); totalbytes = getBytesTotal(); frame = int(loadedbytes/(totalbytes/100)); if (frame > 100) { frame = 100; } if (loadedbytes == totalbytes) { // this takes you to the next scene gotoAndPlay(5); }
you should create something more general so it can be used to preload all your loads. you can create a preload function that contains the useful parts of your code and call that preload function repeatedly using setInterval(). pass the target movieclip or _level and the destination frame to the preload function and your set. here's an example: function preloadF(mc,destination){ loadedbytes=eval(mc).getBytesLoaded(); totalbytes=eval(mc).getBytesTotal(); frame=Math.round(loadedbytes*100/totalbytes); if(loadedbytes==totalbytes){ clearInterval(preloadI); _root.gotoAndPlay(destination); } } p.s. eliminate your frame loop. here are two examples of how to use this function: 1) targetMC.loadMovie("myswf.swf"); preloadI=setInterval(preloadF,100,targetMC,5); 2) loadMovieNum("myswf.swf",23); preloadI=setInterval(preloadF,100,"_level23",5);
Thanks! I'll take a look and see if I can get this to work. A few quick questions since I'm a newbie to Action Script and I get confused as to "placeholder names" and actual code needed when people give me code: (sorry - you can mock me if you like!) 1) Are the 'mc' and 'destination' variables or are those names that I would fill in (runningmanMC,_level23) AND/OR is the mc a MovieClip symbol that I'm "loadMovieNum" the external SWF into? 2) The "setInterval" function (if it's a function?? I'm just learning the terms and often getting them wrong) what are the two numbers in among the four things: the 100 and the 5?
in the preloadF(mc,destination) function. mc and destination are parameters that you pass when you use setInterval(). the first parameter in setInterval() is the name of the function to call, the 2nd is the frequency of calls in mseconds and the rest are passed to the called function. so, in example 1) setInterval(preloadF,100,targetMC,5) you are calling preloadF(mc,destination) every 100 ms and you are passing targetMC to mc and 5 to destination. ie, preloadF() is checking the load progress into targetMC and after loading is complete will direct the _root timeline to frame 5. in example 2) everything is the same except you're loading into _level23. because _level23 probably doesn't exist when you call preloadF(), you pass a string "_level23" to preloadF() and that string is resolved into an object by the eval() function.
Wow - this is really helpful. Thank you. Ok - a few more questions: 1) The first function definition that you wrote: (Function preloadF(mc,destination){ . . . .) That will go on the first frame? 2) The second part that calls the defined function - preloadF - can that then just go on the same action frame below the defined function or does that need to go on the next action frame? 3) Since I have 7 SWF's that are rather large, I want to load them all at once because it's a 3D rendered animation in pieces (and bitmap images). Can I just stack the loads together in the same frame- ie: loadMovieNum("one.swf",15); preloadI=setInterval(preloadF,100,"_level15",5); loadMovieNum("two.swf",16); preloadI=setInterval(preloadF,100,"_level16",5); loadMovieNum("three.swf",17); preloadI=setInterval(preloadF,100,"_level17",5); etc . . . . 4) Ok so it's four questions - I'm feeling needy!! For the "loading" animation that runs (probably just a simple MC) - do I just put that in the same frame as the 'loadMovieNum("one.w.......) code? Thanks for your incredible patience.
1) yes, that would work. it should appear before it is called and could be placed on any timeline. 2) preloadI=setInterval() can go anywhere on the timeline that contains preloadF(). using the correct path reference it can go on any timeline. 3) if you're going to load more than one swf at a time we'll need to tweak that code, slightly: preloadA=new Array(); ind=0; function preloadF(mc,destination,ind){ loadedbytes=eval(mc).getBytesLoaded(); totalbytes=eval(mc).getBytesTotal(); frame=Math.round(loadedbytes*100/totalbytes); if(loadedbytes==totalbytes){ clearInterval(preloadA[ind]); _root.gotoAndPlay(destination); } } then when you would use: loadMovieNum("one.swf",15); preloadA[ind]=setInterval(preloadF,100,"_level15",5,ind); ind++; loadMovieNum("two.swf",16); preloadA[ind]=setInterval(preloadF,100,"_level16",5,ind); ind++; loadMovieNum("three.swf",17); preloadA[ind]=setInterval(preloadF,100,"_level17",5,ind); ind++; etc. or even easier: mySWFs=["one.swf","two.swf","three.swf",..]; for(var ivar=0;ivar<mySWFs.length;ivar++){ loadMovieNum(mySWFs[ivar],15+ivar); preloadA[ivar]=setInterval(preloadF,100,"_level"+(15+ivar),5,ivar); } p.s. you're going to repeatedly send your _root timeline to frame 5 after each load. i'm not sure you want to do that.
Holy crap. Ok - so what is the 'ind' for in all of this new code. And it looks like you're advancing it (adding 1 to it with the ++). So to answer your #4 question - yes - I'd probably want it to play the intro animation the whole time everything is loading. The actual animations are so short that there won't be time to load each one. Here's a link - now the loading code is not fixed yet but at least you can see what I'm working with. http://www.snyderroofing.com/presentation/index.html. You will get a blank screen with two black buttons on the bottom that will sit there until the 2-3mb first movie loads. Once the cut out shows you can click in the lower right corner of the screen and then the second movie will load up and so on. I still have a bunch of work to do on the shell and presentation - but I had to learn Strata 3D just to build this project from scratch - (long story). And to deal with your p.s. below - (to not have it go to frame 5 after each load) maybe not efficient but simple to put each 'setinterval' on a separate frame and then just hopscotch it forward until it's done. ?? So what do you do for a living?
Holy crap. Ok - so what is the 'ind' for in all of this new code. And it looks like you're advancing it (adding 1 to it with the ++). So to answer your #4 question - yes - I'd probably want it to play the intro animation the whole time everything is loading. The actual animations are so short that there won't be time to load each one. Here's a link - now the loading code is not fixed yet but at least you can see what I'm working with. http://www.snyderroofing.com/presentation/index.html. You will get a blank screen with two black buttons on the bottom that will sit there until the 2-3mb first movie loads. Once the cut out shows you can click in the lower right corner of the screen and then the second movie will load up and so on. I still have a bunch of work to do on the shell and presentation - but I had to learn Strata 3D just to build this project from scratch - (long story). And to deal with your p.s. below - (to not have it go to frame 5 after each load) maybe not efficient but simple to put each 'setinterval' on a separate frame and then just hopscotch it forward until it's done. ?? So what do you do for a living?
ind is the index of the array playA(). we need to use a distinct variable for each distinct setInterval() in order to terminate the repeated function calls with clearInterval(). if we use the same name (like playI) for each setInterval(), when we execute clearInterval(playI) only the most recently defined setInterval() will terminate and the rest will continue to repeatedly call playF(). to preload all you movies before going to frame 5, we can use: numLoadsCompleted=0; function preloadF(mc,destination,ind){ loadedbytes=eval(mc).getBytesLoaded(); totalbytes=eval(mc).getBytesTotal(); frame=Math.round(loadedbytes*100/totalbytes); if(loadedbytes==totalbytes){ clearInterval(preloadA[ind]); numLoadsCompleted++; if(numLoadsCompleted==playA.length){ _root.gotoAndPlay(destination); } } }
I'm trying to start simple since dropping in the more complicated code and tweeking it to match my file names didn't work for me. I must be missing something. So, I'm using the first example of the code you sent and it still jumps ahead to the frame with the "_level01.play();" and waits for the movie to load. Is there something I'm missing? Here's a directory with the native FLA file and an html page showing what happens: http://www.echopdx.com/3d Thanks
Wow - (I'm on a mac) and I tried it in all three browsers I have (IE, Netscape & Safari) and it jumped right to frame six and waited for the file to download ( I put the frame number in each frame to ensure I knew what frame it was on) but I tested it on the PC we have here and it worked!!! Thanks for your help - this is going to run on a pc anyway so I'm going to play with the other code now to see if I can get those to work in the PC browser. You're awesome! I appreciate your patience with a newbie. Any books you'd suggest to begin learning ActionScript? I have one of those huge Flash reference books/bibles, but I think I need to learn it from the begining (what parameters are, what method and properties are - all the lingo). Or maybe I should take a class - that might be faster for the uptake. Thanks again.
you may have old flash plug-ins in those other browsers. go to macromedia.com and update the flash plug-in, if you want to use those other browsers. as for book recommendations, i don't have any. i've learned from reading this forum's questions and answers, when i first started "formal" learning, and then from answering other's questions when i felt i could contribute. however, there are book recommendations that have bee posted before in this forum. a search should reveal the handful that others have found helpful. good luck and you're very welcome!
Don't see what you're looking for? Try a search.
|