Section 9.2. Controlling External Videos


9.2. Controlling External Videos

In this section, you will learn how to use components to control external video, and how to write your own control scripts. Using external video in Flash is very similar to using external sound. The major difference between external video and external sound is that FLV video files are only used by the Flash platform, making them a bit harder to create and repurpose than MP3 audio files. Fortunately, a variety of tools exist to create FLV files, including two that ship with Flash.

9.2.1. Encoding

The most rudimentary way to encode videos into FLV format is to use the Import Video Wizard, just as you did during the "Preparing Video for Import into Flash" section of this chapter. This may not make sense given the name of the wizard, but the same process you used earlier can also create external FLV files. Instead of embedding the video, the wizard will create an external FLV and configure your new file with the new FLVPlayback component.


Note: Depending on the source material, the speed of your computer, and the software you are using, it can take a long time to encode a video into FLV format. If you are most interested in the step-by-step process of this project and wish to leave the long encoding process until later, you have two options. First, you can use the small video you imported in the previous section, extreme_sports_ loop.mov, instead of the suggested nero.mov. Second, you can read this section without following the steps and use the nero_01.flv file provided on the CD-ROM in the 09 folder.

Flash's Import Video Wizard saves external video files in the same location as the currently active document. Therefore, you must have a recently saved file open for the wizard to determine an export path. Here's how it works:

  1. Create a new document called nero1.fla and save it in your 09 folder. Use Modify Document to give it dimensions of 320 x 280.

  2. Import Import Video menu option to show the Import Video Wizard again. On the Select Video screen, choose the default option, "On your computer," and find the 09 folder. When you're ready, press the Continue button.

  3. On the Deployment screen, select "Progressive download from a web server." This format will also work locally, for testing and disc-based distribution (e.g., for kiosks and CD-ROMs).

  4. Because you are not embedding this video, the next screen is the Encoding screen. This time, choose "Flash 8 - Medium Quality (400 kbps)." This option uses On2's VP6 codec, new to Flash 8. The Flash 8 Player is required to play back this FLV file. When you're ready, press Continue.


    Note: Although the Flash 8 Player is required to display FLV files compressed with On2's VP6 codec, you do not have to update Flash 6 or 7 .swf files to load the external video assets. As long as the end user has the Flash 8 Player, the FLV will also work when loaded into Flash 6 or 7 .swf files.On2's VP6 provides superior quality at smaller data rates than Sorenson Spark, and also supports alpha channels. This means you can reproduce things like fire, smoke, fog, and similar effects that require alpha data, compositing the video with your other Flash assets live at runtime.However, VP6 is more processor-intensive than Spark, so performance may be an issue on older machines. This is especially true when playing videos with alpha data. Therefore, it's a good idea to test your files on a machine that is as close as possible to your intended lowest common denominator.

  5. A new screen called Skinning will appear. Choose "SteelExternalAll. swf" for the skin. Your screen should look like Figure 9-3.

    Figure 9-3. The Skinning screen of the Video Import Wizard

    The built-in Video Import Wizard provides a shortcut: it will set up the active .fla with the new FLVPlayback component and automatically link to your newly compressed FLV file. The "SteelExternalAll.swf" option provides a full-function controller that is external to your FLV. Other colors and partial feature sets are also available, including versions that appear above and inside the bounding area of your video. (You can also use your own custom skin, if you've already created one.) You will look at this component again later, so when you're finished previewing the presets in the menu, press Continue.

    After presenting a summary screen, Flash will compress the video into FLV format and save it in the same directory as your active document. When the process is complete, it will return you to your main document, having added the FLVPlayback component and preselected the controller you chose earlier. To finish:

  6. Click the display area of the component and, using the Properties panel, position it at (0, 0).

  7. Save your work and test your movie.

Your file should publish very quickly (because all assets are external) and show the video, complete with controller, for you to use. You will learn how to configure options of the controller in an upcoming section of this chapter.

9.2.2. Standalone encoding applications

While it's convenient to encode FLV files from within Flash, doing so can take longer and yield poorer results than encoding with a dedicated FLV compression tool. Fortunately, two additional pieces of software ship with Flash 8 Professional.

The first is the Flash 8 Video Encoder. Essentially, this is a standalone version of the encoder built into Flash. However, it appears to produce better results faster, and it offers the huge benefit of supporting batch processing. The interface, beyond the batch-processing window, is the same for the most part.

The second piece of software is the Flash 8 Video Exporter. During the installation of Flash 8 Professional, the Exporter is installed and made available to any QuickTime-savvy application. Although, as a codec, it can't offer batch processing, it can be handy to export to FLV from within your favorite video editing application. The Exporter, too, shares essentially the same interface as Flash's Video Import Wizard and the Flash 8 Video Encoder.

Third-party tools are also available. Although requiring an additional purchase, they typically offer better, faster results than the aforementioned solutions that ship with Flash. There are two major tools in this market, but others exist. The companion web site to this book, http://www.flash8projects.com, will host a regularly updated list of Flash resources that will include additional information about encoders.

The first major third-party tool is Sorenson Squeeze. As the developers of the original Flash video codec, Sorenson Spark, they have experience compressing for Flash and have created a sturdy tool that is also easy to use. At the time of this writing, Sorenson had announced support not only for their own Spark codec, but for On2's VP6 codec, making it possible for Squeeze to compress FLV files that take full advantage of Flash 8's features. See Appendix A for more information about Squeeze.

The second major third-party FLV compression application is the Flix Flash 8 Video Encoder, by the makers of the Flash 8 video VP6 codec, On2. Flix is a powerful, feature-rich tool that offers a host of features, including expanded file support and the ability to vectorize video for interesting effects. Most notable, however, is the fact that the version of Flix that was current as of this writing compressed files that were as much as 25% to 30% smaller than those produced by any other exporter. See Appendix A for more information about Flix.

9.2.3. Streaming Versus Progressive Download

Talk about streaming video abounds, but unless you're using dedicated streaming server software, you're probably not working with streaming video. Instead, you are probably working with a pseudo-streaming technology sometimes called fast start or quick start. These technologies effectively pre-fetch or buffer a portion of the video and then allow playback while downloading the remaining content.

This approach is also commonly called progressive download, because the asset is downloaded in progressive stages without affecting playback too much. FLV files encoded for progressive download can also be used locally, and these will be the focus of the video projects in this book.

The Flash platform includes a streaming server, currently called Flash Media Server 2. (Until recently, it was called the Flash Communication Server.) Use of this server is outside the scope of this text, but additional information is available online, including at Macromedia's web site (http://www.macromedia.com/software/flashmediaserver/).

9.2.4. FLV Components

The FLVPlayback component is the new Flash 8 version of the media components you used in Chapter 8. It only works with FLV files, not MP3 files. Even if you ended up with a working component after the in-Flash video encoding example, start from scratch now to see how easy the FLVPlayback component is to use:

  1. Create a new file and save it as nero2.fla in your 09 folder. (Don't worry if you don't have a nero1.fla. That just means you chose not to encode the sample video in the previous project.) Set the stage dimensions to 320 x 280.

  2. Drag the FLVPlayback component to the Stage and position it at (0, 0).

  3. With the FLVPlayback component on the Stage selected, open the Component Inspector, click on the contentPath parameter field or its associated magnifying glass button, and find the nero_01.flv file in the 09 folder. Repeat this process for the skin parameter, and choose the controller you prefer. (If you want to match the sample file provided, choose an External All option, such as "ArcticExternalAll.swf.")

  4. Save and test your movie. If you want to compare your file to the provided source, it should match nero_01.fla. Don't close your file, however, as you can jump-start the next project with it.

That's all there is to it. You should now be able to control your external video with the controller, as seen in Figure 9-4. There's one important thing to know about the FLVPlayback component, though. The controller is an external .swf file that is automatically loaded by the component. Look in the 09 directory after testing your movie, and you will see that the controller skin you chose has been copied to this directory. This file is also required when distributing your files.

Figure 9-4. The FLVPlayback component, with full controller, playing an external FLV file


You're not stuck with the preset controllers when using the FLVPlayback component. When you are experienced enough to create your own custom skin, you can select that file instead. That requires a bit of ActionScript, some of which you will learn in this chapter, but some that you'll have to become comfortable with on your own.

However, in the meantime, you can build your own controller, piece by piece:

  1. Use the File Save As command to save your current file as 09 folder.

  2. Select the FLVPlayback component and open the Component Inspector. Click on the skin parameter field and select "none." You still have the FLVPlayback component configured to show the nero_01.flv file, but it will not display a controller.

  3. Open the Components panel and look inside the FLV Playback Custom UI component category. You can use these pieces to build a controller any way you want, with very little scripting. All of the components will function the way you expect them to, and all you'll have to do is associate them with the FLVPlayback component.

  4. For brevity, drag just the PlayPauseButton and StopButton components to the Stage, and position them anywhere beneath the FLVPlayback component.

  5. Select the display playback component and give it an instance name of flvplayer. Then select the two buttons and give them instance names of playPause_btn and stop_btn, respectively.


    Note: These components are not really buttons, but the _btn suffix will not alter their functionality and may help you remember what each object is at a glance. If you want to be strict about your naming conventions, you can change these names, as long as you do so again in the following script.

  6. Finally, add the following script to frame 1:

     flvplayer.autoPlay = false; flvplayer.playPauseButton = playPause_btn; flvplayer.stopButton = stop_btn; 

The first line prevents the video from playing automatically, as a change from your prior projects. The second and third lines use the playPauseButton and stopButton properties to identify the component instance names of the components that serve these purposes. Just by making this assignment, you'll enable the buttons to control your video. Think of the button components as already scripted but with nothing to control. Once you pair them with an FLVPlayback display, they will work together.



Flash 8(c) Projects for Learning Animation and Interactivity
Flash 8: Projects for Learning Animation and Interactivity (OReilly Digital Studio)
ISBN: 0596102232
EAN: 2147483647
Year: 2006
Pages: 117

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