Loading Movies

I l @ ve RuBoard

Throughout this book you have made several movies that were not part of the main zoo movie. In the next exercise you will load these movies into the main movie. This is another technique you can use to create a more enjoyable experience for usersinstead of having to download one enormous file containing everything, visitors can download the content they want to see. In this exercise you'll use the loadMovieNum action to load .swf files into the main movie. The loadMovieNum action lets you load a .swf file into a level of the Flash Player while the original movie is still playing. In this project, the original movie is the zoo36.fla movie (zoo36.swf when it's exported). The movies you are going to load will be the movies you created in previous lessons, including the map and guestbook you worked on in Lesson 9.

You should still have zoo36.fla from the last exercise open when you start this exercise.

  1. Select frame 1 of the Actions layer. Modify the menu array so it looks like the following:

      menu = new Array();   menu[0] = ["home", "main.swf"];   menu[1] = ["featured creature", "feature.swf"];   menu[2] = ["visitor info", "visitorinfo.swf"];   menu[3] = ["map", "map.swf"];   menu[4] = ["games", "games.swf"];   menu[5] = ["guestbook", "guestbook.swf"];  

    graphics/11fig30.gif

    When you modify the menu array as instructed, you are creating a multidimensional array. That means that each element in the array contains an array. In this case, each menu array element will have two elements of its own. It's sort of like writing this:

      menu[0] = new Array("home", "main.swf");  

    This gives the menu[0] element of the menu array two elements: "home" and "main.swf" . The first element provides the text for the menu item, while the second element will be the .swf file that loads when the menu item is clicked.

  2. Modify line 31 of the ActionScript in frame 1 of the Actions layer so it uses the first element in each item in the menu array for the text in each menu piece:

      menuClip["item"+i].mtext = menu[i][0];  

    graphics/11fig31.gif

    This code is in the for statement that's about halfway down in the Actions panel. It should look like the following when you've made your change:

      for (var i=0; i<menu.length; i++) {   menuClip.attachMovie("mpiece", "item"+i, ++cDepth);  menuClip["item"+i].mtext = menu[i][0];  menuClip["item"+i]._y = menuClip.top._height +   menuClip["item"+i]._height*i;   menuClip["item"+i].useHandCursor = false;   menuClip["item"+i].onRollOver = function () {   this.t.backgroundColor = 0xFF6600;   this.t.textColor = 0xFFFFFF;   }   menuClip["item"+i].onRollOut = function () {   this.t.backgroundColor = 0xFFFFFF;   this.t.textColor = 0xCC0000;   }   }  

    Since each element in the menu array now contains an array, referring to menu[i] in the for statement will refer to an array. You want to refer to the first element in the menu[i] array. You can do this by referencing the first index in that array, which is 0.

  3. Add a new line after line 41 in the Actions panel, and add the following ActionScript:

      menuClip["item">+i].swf = menu[i][1];   menuClip["item"+i].onPress = function() {   loadMovieNum(this.swf, 2);   };  

    graphics/11fig32.gif

    TIP

    Click the Auto Format button in the Actions panel, and Flash will automatically indent your ActionScript where appropriate. Flash will also add semicolons at the ends of any lines that should have one.

    The for statement that creates all the menu pieces should now look like the following:

      for (var i = 0; i<menu.length; i++) {   menuClip.attachMovie("mpiece", "item"+i, ++cDepth);   menuClip["item"+i].mtext = menu[i][0];   menuClip["item"+i]._y = menuClip.top._height+menuClip["item"+i]._height*I;   menuClip["item"+i].useHandCursor = false;   menuClip["item"+i].onRollOver = function() {   this.t.backgroundColor = 0xFF6600;   this.t.textColor = 0xFFFFFF;   }   menuClip["item"+i].onRollOut = function() {   this.t.backgroundColor = 0xFFFFFF;   this.t.textColor = 0xCC0000;   }  menuClip["item"+i].swf = menu[i][1];   menuClip["item"+i].onPress = function() {     loadMovieNum(this.swf, 2);  };   }  

    The first line of the ActionScript you just added initializes a new variable, called swf , in the instance of the Menu Clip movie clip named "item"+i . The value of the new swf variable is set to the value of the second element in the i th array elementthe value of i is set by the for statement.

    The next part of the code you added sets the onPress event for the menu piece. When the instance of the Menu Clip movie clip is pressed, the loadMovieNum action is triggered. The loadMovieNum action has the following syntax:

      loadMovieNum(url, level);  

    The url argument contains the URL of the .swf file that you want to load. The level is much like a layer. Levels have a stacking order. The movie that Flash Player loads (the movie you're working with) is in level 0. In this case, you are loading this.swf , which refers to the value of the swf variable in each menu item, into level 2, so it will be above the current movie in the level stacking order.

  4. Open visitorinfo 1 .fla from the FlashTFS folder.Move frame 1 of the Contents layer to frame 2.

    graphics/11fig33.gif

    You made the visitorinfo1.fla file in Lesson 5you should have a copy of it in the FlashTFS folder. If you can't find visitorinfo1.fla in the FlashTFS folder, there's a copy of it in the Lesson11/Starting folder on the CD-ROM.

    To move frame 1 of the Contents layer to frame 2, you can copy and paste the frame. Or you can select frame 1, release the mouse, and then click and drag the selected frame to frame 2. Use whichever method is easierjust make sure frame 1 ends up empty and all of your content is in frame 2.

  5. Add a keyframe to frame 2 of the Actions layer in visitorinfo1.fla. Add a stop action to this new keyframe, and set the Frame label to rf. Export the movie as visitorinfo.swf in the FlashTFS folder, and save the file as visitorinfo2.fla in the FlashTFS folder.

    graphics/11fig34.gif

    Select frame 2 of the Actions layer in visitorinfo1.fla, and choose Insert > Keyframe or press F6. Select the new keyframe, and add a stop action in the Actions panel by typing stop(). After you add the stop action to frame 2, be sure to set the Frame label, in the Property inspector, to rf. This Frame label will be very important in Lesson 12, when you create a preloader for your project.

    Now it's time to export the movie. Choose File > Export Movie. In the Export Movie dialog box, browse to the FlashTFS folder on your hard drive, enter visitorinfo.swf in the File Name (Windows) or Save As (Macintosh) box, and click Save. When the Export Flash Player dialog box opens, leave the settings at their defaults and click OK.

    When you're done exporting the movie, save the .fla file as visitorinfo2.fla in the FlashTFS folder. You're going to work with that file again in Lesson 12.

  6. Repeat steps 4 and 5 for feature1.fla, map8.fla, and guestbook8.fla from the FlashTFS folder.

    If you can't find these files in the FlashTFS folder, you can find copies of them in the Lesson11/Assets folder on the CD-ROM.

    Move frame 1 of the Contents layer in feature1.fla to frame 2. Then add a keyframe to frame 2 of the Actions layer, add a stop action in that keyframe, and set the Frame label for that keyframe to rf. Export feature1.fla, which you created in Lesson 6, as feature.swf. Save feature1.fla as feature2.flayou're going to work with that file again in Lesson 12. Save the .fla file in the FlashTFS folder on your hard drive, which is the same place where you should save the .swf file.

    graphics/11fig35.gif

    TIP

    You can easily switch between multiple open movies using the Window menu. Just choose Window and the name of the open .fla file you'd like to work with, as illustrated by the figure below.

    graphics/11fig36.gif

    When you're ready to modify guestbook8.fla, things will be a bit more complicated than they were for feature1.fla. For guestbook8.fla, you should move frame 1 of the Actions, Components, Text Boxes, and Background layers to frame 2 of that movie. Make sure that you move the Actions that were in frame 1 of the original movie to frame 2; otherwise you'll find that parts of the movie will not work correctly. Add a stop action to the end of the ActionScript in frame 2. Finally, set the Frame label for frame 2 of the Actions layer to rf. Export the movie as guestbook.swf and save the file as guestbook9.fla.

    graphics/11fig37.gif

    Modifying map8.fla is also a little more complicated. For map8.fla, move frame 1 of the Actions, Printable Content, List, Locations, and Map layers to frame 2. Add the stop action at the end of the ActionScript in frame 2. The label in frame 2 is already !#p, which disables the Print command in the Flash Player contextual menuchange that label to rf.

    graphics/11fig38.gif

    NOTE

    If you'd like to keep the Print command in the Flash Player contextual menu disabled for the ZooMX Web site, simply set the Frame label for frame 1 in zoo36.fla to !#p.

  7. Return to zoo36.fla and choose Control > Test Movie.

    graphics/11fig39.gif

    When you test the movie, you should notice that the contents of the top1.fla file, which you exported as top.swf, do not appear. The contents of main1.fla, which you exported as main.swf, also don't appear unless you click the home menu item. That's because you haven't added ActionScript to load those movies when the Web site appears. You'll do that in Lesson 12.

    Click each of the menu items. All except the games menu item should load a movie into level 2. When the movies load into level 2, they will obscure the menu, so you might have to move the menu off to the side so you can keep selecting items from it. You will fix that in Lesson 12, so the menu will appear above all of the loaded movies.

    TIP

    If you forgot to add a stop action in frame 2 of any of the loaded movies, the loaded movie may flicker. To fix the flickering , open the offending movie's .fla file and add a stop action to frame 2 of the Actions layer. Then export the movie to the FlashTFS folder, using the appropriate name, and test zoo36.fla again.

  8. Close the Test Movie window, and save the file as zoo37.fla.

    When you're finished testing the menu, close the Test Movie window. Save the file as zoo37.fla in the FlashTFS folder on your hard drive. You're done with this file for this lesson, so you can close it.

I l @ ve RuBoard


Macromedia Flash MX. Training from the Source
Macromedia Flash MX: Training from the Source
ISBN: 0201794829
EAN: 2147483647
Year: 2002
Pages: 115
Authors: Chrissy Rey

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net