in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

macromedia flash mx - Reinhardt R.

Reinhardt R., Lott J macromedia flash mx - John Wiley & Sons, 2004. - 987 p.
ISBN 0-7645-4354-7
Download (direct link): macromediaflash2004.pdf
Previous << 1 .. 365 366 367 368 369 370 < 371 > 372 373 374 375 376 377 .. 419 >> Next

16. Create another layer and name it textfield. Place this layer at the bottom of the layer stack in the loaderClip symbol.
17. Select the Text tool and create a Dynamic text field on frame 1 of the textfield l ayer. Place the text field underneath the mcBar instance, as shown in Figure 34-10. In the <Instance Name> field of the Property inspector, name the text field tPercent. You will use this text field to display what percentage of the Flash movie is currently loaded. You do not need to enable the Show Border (or other options) for this text field.
18. Go back to the main timeline (that is, Scene 1). Select the mcLoader instance on the stage and center it using the Align panel. Select frame 10 of the mcLoader l ayer and insert an empty keyframe (F7). You need only the mcLoader instance to appear as the movie is preloading.
19. Create a new layer and name it actions. Place this layer underneath the labels layer.
20. Select frame 1 of the actions layer and open the Actions panel. In the Script pane, insert the code shown in Listing 34-1. Each line of code is explained in comments within the code. If you don’t want to type this code, you can copy the contents of the file (located in the ch34 folder of the CD-ROM), or you can attach the AS file to this frame with an #include directive.
ii ¡ Transform
+*¦ 1,0% t 100.0% ? Constrain
0R<rtate ^ 0.0°
Î skew 127
_as. a
828 Part X ¦ Creating Flash Applications
Figure 34-10: The tPercent field displays what percentage of the movie is currently loaded.
Listing 34-1: The checkLoad( ) Function
function checkLoad(mcTarget:MovieClip):Void{
// nLBytes stores the current bytes that have loaded
var nLBytes:Number = mcTarget.getBytesLoaded();
// nTBytes stores the total bytes of the movie
var nTBytes:Number = mcTarget.getBytesTotal();
// nPercent calculates the percent of the movie that // has loaded into the Flash Player.
var nPercent:Number = (nLBytes/nTBytes)*100;
// Apply the nPercent value to the X scale of the // mcBar instance within the mcLoader instance
mcLoader.mcBar._xscale = nPercent;
Chapter 34 ¦ Managing and Loading Flash Content 829
// Fill the tPercent field within the mcLoader instance // with the nPercent value followed by the text // "% of " and the total kilobytes of the movie. For // example, when half of a 64K movie has loaded, the text // field will display "50% of 64K loaded."
var sPercent:String = Math.floor(nPercent).toString(); var sKBytes:String = Math.floor(nTBytes/1024).toString(); var sMessage:String = sPercent + "% of " + sKBytes + "K loaded."; mcLoader.tPercent.text = sMessage;
// If the loaded bytes are greater than or equal to the // total bytes of the movie and the total bytes are // greater than 0
if (nLBytes >= nTBytes && nTBytes > 0) {
// Check to see if the nCount variable is greater than
// or equal to 12. If it is, execute the nested code.
// This if/else code pauses the movie once 100% of the
// movie has loaded into the Flash Player.
if (nCount >= 12) {
// exit the loading sequence by removing the // setlnterval ID established later in this frame
// jump to the "main" frame
// otherwise, if the movie has completely loaded and // nCount is less than 12.
} else {
// add 1 to the count variable nCount++;
// continue executing the checkLoad() function with // setInterval(). There is no further code to insert // here, as this will happen automatically if // clearInterval() is not executed.
// force the stage to refresh the screen independent of // the frame rate of the movie
830 Part X ¦ Creating Flash Applications
Listing 34-1 (continued)
// Initialize a count variable (to pause the loader briefly // at 100%) with a value of 0
var nCount:Number = 0;
// As soon as this frame is played, start executing the
// the checkLoad() function continuously, passing a
// reference of the Flash movie (this) as an argument
var nProgress:Number = setInterval(checkLoad, 100, this);
// stop the movie
21. Save your Flash document as checkLoad_100.fla and test it (Ctrl+Enter or ^+Enter). When you enter Test Movie mode, choose View Î Show Streaming, or press Ctrl+Enter or ^+Enter again. As shown in Figure 34-11, you will see the movie’s download progress reflected in the _xscale property of the mcBar i nstance, as well as an updated percent value and the total file size in the tPercent field. When the movie is fully loaded, the loader will pause for about a second and go to the main l abel.
You can find the completed file, checkLoad_100.fla, in the ch34 folder of the book's CD-ROM.
Figure 34-11: The progress bar will grow as the movie loads into the Flash Player.
Chapter 34 ¦ Managing and Loading Flash Content
Once you have this example working properly, you can copy and paste the preload frame and mcLoader instance into other Flash movies. For small Flash projects, you might simply want to build an internal preloader for every Flash movie you develop. However, if you will be loading several assets into the Flash movie, you might need some that can adapt to different file types. In the next section, you learn how to make a preloader that can be dynamically attached to the movie to monitor the loading progress of several file types.
Previous << 1 .. 365 366 367 368 369 370 < 371 > 372 373 374 375 376 377 .. 419 >> Next