Using the MediaPlayback component

Suppose you must develop a website that allows users to preview DVDs and CDs that you sell in a rich media environment. The following example shows the steps involves. (It assumes your website is ready for inserting streaming components.)

To create a Flash document that displays a CD or DVD preview:

  1. Select File > New and choose Flash File (ActionScript 2.0).
  2. Open the Components panel and double-click the MediaPlayback component to place an instance of it on the Stage.
  3. Select the MediaPlayback component instance and enter the instance name myMedia in the Property inspector.
  4. In the Component inspector, set your media type according to the type of media that will be streaming (MP3 or FLV).
  5. If you selected FLV, enter the duration of the video in the Video Length text boxes; use the format HH:MM:SS.
  6. Enter the location of your preview video in the URL text box. For example, you might enter http://www.helpexamples.com/flash/video/clouds.flv.
  7. Set the desired options for the Automatically Play, Use Preferred Media Size, and Respect Aspect Ratio check boxes.
  8. Set the control placement to the desired side of the MediaPlayback component.
  9. Add a cue point toward the end of the media by clicking the Add (+) button; this cue point is used with a listener to open a pop-up window that announces that the movie is on sale. Give the cue point the name cuePointName and a position near the end of your media duration.
  10. Drag a Window component from the Components panel to the current document's library.

    This places a symbol called Window in your library, and makes the Window component available to your SWF file at runtime.

  11. Create a text box and write some text informing the user that the movie is on sale.
  12. Select Modify > Convert to Symbol to convert the text box to a movie clip, and name it mySale_mc.
  13. Right-click (Windows) or Control-click (Macintosh) the mySale_mc movie clip in the library, select Linkage, and select Export for ActionScript. Make sure the Linkage Identifier is correctly named.

    This places the movie clip in your runtime library.

  14. Remove the text box from the Stage.

    The text box only needs to be in the Library.

  15. Add the following ActionScript to Frame 1. This code creates a listener to open a pop-up window informing the user that the movie is on sale.
    // Import the classes necessary to create the pop-up window dynamically. 
    
    import mx.containers.Window;
    import mx.managers.PopUpManager;
    
    // Create a listener object to open sale pop-up. 
    var saleListener:Object = new Object();
    
    saleListener.cuePoint = function(eventObj:Object) {
    
    var saleWin:MovieClip = PopUpManager.createPopUp(_root, Window, false, {closeButton:true, title:"Movie Sale", contentPath:"mySale_mc"});
    
    // Enlarge the window so that the content fits.
    
    saleWin.setSize(80, 80); 
    var delSaleWin:Object = new Object(); 
    delSaleWin.click = function(eventObj:Object) { 
        saleWin.deletePopUp(); 
    }
    saleWin.addEventListener("click", delSaleWin); 
    
    }
    
    myMedia.addEventListener("cuePoint", saleListener);
    
  16. Select Control > Test Movie to test the SWF file.

    When the application reaches the playback time of the cuePointName cue point, a window pops up to show your message.


Flash CS3