Preloaders, Rererevisited

Well, I finaly got to it. :slight_smile: sleep helps.\r\rOk, there are two things that the uninitiated needs to know about preloaders right off the bat. They are A) the loop, and B) get properties functions.\r\rEvery time you need to check for something over and over in flash, the best way is to make a loop, out of the action script. Frame loops are the most common, so I’m going to cover them in this post, then we’ll move on to onClipEvent (enterFrame) loops.\r\r* If you don’t have a blank layer, just for action script, then I suggest that you make one. Nothing annoys more than having to search through FLA files for the action script.\r\r1) Create a blank layer, and create a second frame on that layer.\r\r2) With the second frame selected, open the “Action” panel, and insert the following action script.\r\rgotoAndPlay(1);\r\r There you have it… that’s a loop. The play head will reach frame one, go on to frame two, and when it reaches the action script, it will loop back to frame one again.\rNow we need some script in frame one to get some properties of the movie. Alot of people like to use framesLoaded. I do not. framesLoaded might be useful if you are trying to test to see if a particuar frame is loaded, but most of us are interested in the total killobytes, and the number of killobytes that have loaded. I use the getBytesTotal();, and the getBytesLoaded(); commands.\r\r3) With frame one selected, enter the following code. I’ve added “//” in some of these lines. They will show up pink in your action script panel. They are comments and are not important to the Flash player, but should help you to understand what is happening in the code.\r\r//here we are getting the total bytes and the number of \r//bytes that have been loaded so far, of the movie, and \r//dividing it by 1000 in order to come up with killobytes.\r//we set two variables to be equal to these two statements \r//like so\rtotalK=getBytesTotal()/1000;\rloadedK=getBytesLoaded()/1000;\r//remaining K is just the first variable, minus the second.\rremainingK=totalK-loadedK;\r//percentage of K loaded is just the second variable divided \r//by the first, and then mutliplied by 100.\rpercentageK=(loadedK/totalK)100;\r//here we set the bar movie clip to scale, left/right by the \r//amount of the percentage variable.\rsetProperty(“bar”,_xscale,percentageK);\r//here is our break out… if the amount of K loaded is greater \r//than the total K of the movie, AND (that’s what && means… \r//both conditions have to be true) the total K is NOT equal to \r//0, then goto the third frame. \rif(loadedK>=totalK&&totalK!=0){\r gotoAndPlay(3);\r}\r\r we need to create a percentage bar\r4) Create a new layer.\r\r4a) On the main stage, create a square of fill, with no stroke. \r\r4b) Click on it once to select it, then open your “info” panel. In the height and width fields, enter 20 for height, and 200 for width. Hit enter after making each entry.\r\r4c) With the rectangle still selected, hit F8, and in the dialogue box that opens, select Movie Clip. The name can be anything.\r\r4d) Double click on the bar movie clip to edit it in place. When you’re inside the movie clip, select the fill and move it to the right, until it’s left side is flush with the small cross hair, representing the middle of the clip.\r* why go through this step? Because we are scaling the bar movie clip, we don’t want it to expand from the middle to either end, but rather from one side out to the right. It just looks better, though I’ve also had some that expanded from the middle outwards. It’s really your choice.\r\r4d) Go back to the main stage, select the movie clip, open your “instance” panel, and enter “bar” in the instance name field.\r\r4e) You may wish to create some text that says 0%, 50% 100% or what ever, and place these near the bar, with 0% on the left side and 100% on the right. See my example.\r\r some people like to have text fields display the different K amounts*\r5a) Select the text tool. Open the “text” panel and select “Dynamic text” from the pull down menu. The variable name field, will now allow you to enter something into it. Enter “totalK” in this field.\r5b) Repeat step 5a, two more times, naming each “loadedK”, and “remainingK”.\r5c) If you like, create some plane text labels for these, and possition to your liking. I usually stack them with totalK on top, loadedK in the middle, and remainingK on the bottem.\r\rThat’s really all there is too it.\r\rThe preloaderBar files are located, for download, as open source, here\…derBar.fla\r[url=“”]…derBar.swf\r\rAsk your questions. :slight_smile:

Nice little tute Uppy!\r\rpj\r:cool:

where can i see the live example of the preloder that u have used pls give the url\rEbu

oops… you know… I never posted that. I think because when I made my example I was doing it as a movie clip, but wrote it as if it were on the main timeline… so I didn’t have one to post. I’ll post both the SWF and the FLA in an hour when I get home.

Just a note… a lot of people don’t know about the bandwidth profiler, and streaming settings. These are important if you want to check to see if the preloader is working properly… so I better go over it.\r\rWhen you do a menu option “control/test movie”, a flash player will open. With this player open, click on menu option “view/bandwidth profiler”. This will show you how many bytes are located in each frame of your movie.\rIn addition, under the “view” menu option, there is also a “show streaming” choice. This will let you see the movie, as it would apear, on various connectly speeds. You’ll have to play around a little, but you have all the options you like, right there. You can even create speeds that don’t exist, like 12,560kps, or something like that. It is a very useful tool for those of you interested in knowing exactly what your visitors are likely to be going through to see your stuff.

The preloaderBar files are located, for download, as open source, here\…derBar.fla\r[url=“”]…derBar.swf

Hey, Upu, loose the rat !!!\r\rpom 0]

Thanks so much for your mini tutorial!!\rI would have never figured that out!!\r:)

ok… so here’s an update… since we have new information that I wasn’t aware of before I wrote that.\r\rThis code will work for any object in your movie. That is to say, you can get the bytes information for anything that can be named with an instance name. In MX this would allow someone to target just about anything, but in Flash 5.0 it just means that anything we wish to find out this information on needs to be inside a movie clip. If it has an “instance” name, then you can find out the bytesLoaded, and Total.\r\rwith a large movie clip. You could have a stop action on it’s first frame. Then if it were named myMovieClip, this code would figure out when the clip should start playing.\r\rtotalK=_root.myMovieClip.getBytesTotal()/1000;\rloadedK=_root.myMovieClip.getBytesLoaded()/1000;\rpercentageK=(loadedK/totalK)*100;\rif(loadedK>=totalK&&totalK!=0){\r;\r}

Post on the regular forums, noono, you’re not supposed to use this forum to ask questions :slight_smile:

pom :cowboy:

what? then why aren’t these threads locked? …lol… :stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue: loookit mE MA!! i’m posting on BEST OF KIRUPA!!! WOW I FEEL SO SPECIAL