O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.3. Adding a Video Object at Runtime

Problem

You want to add video (and audio) to a Flash movie at runtime.

Solution

Create a movie clip symbol with an embedded Video object and set it to export for ActionScript.

Discussion

Although there is no way to create a Video object at runtime, you can create a movie clip with an embedded video at authoring time. If you set the movie clip symbol to export for ActionScript, you can add instances of the movie clip (including the embedded video) to your Flash movie at runtime with an attachMovie( ) method, as you would with any other exported movie clip. Here are the steps you should follow:

  1. Open the Library and choose New Video from the Library’s pop-up Options menu to create a new video symbol.

  2. Create a new movie clip symbol (using New Symbol) and drag an instance of the video symbol into it, positioning the video at (0,0).

  3. Name the instance of the video symbol my_video.

  4. Open the linkage settings for the movie clip symbol (by choosing Linkage from the Library’s pop-up Options menu) and select the Export for ActionScript and Export in First Frame checkboxes. Enter a linkage identifier of VideoMcSymbol.

  5. At the point in your ActionScript code where you wish to add a video, use the attachMovie( ) method to attach an instance of VideoMcSymbol, as follows:

    // Create an instance of the video movie clip symbol.
    _root.attachMovie("VideoMcSymbol", "myVideo_mc", 1);
  6. When you want to target the video (to attach a net stream, for example), you should use the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required