Flash Basics > Using shared libraries

Using shared libraries

You can create shared libraries to use assets from one library in multiple Flash movies. To use shared libraries, you define shared library assets in a movie, and then link to those assets from other movies. When you link to an asset in a shared library, the asset is referenced as an external file, but the asset file is not added to the movie.

Using shared libraries can optimize your workflow and movie asset management in numerous ways. For example, you can use shared libraries to do the following:

Share a sound file across a site
Share a font symbol across multiple sites (for information on font symbols, see Creating font symbols)
Provide a single source for elements in animations used across multiple scenes or movies
Create a central resource library to use for tracking and controlling revisions


 
About creating and linking shared assets

To create a shared library that you can use with other movies, you define linkage properties for items in a movie's library. When you save the movie, the shared library is saved with the movie's FLA file.

To use assets from a shared library in another movie, you choose File > Open As Shared Library in the current movie, and select the shared library file that you want to use. The shared library opens as a library window in the current movie. You then add assets from the shared library to the current movie's library to create links to the assets.

You must post a shared library on the Web in order for movies that link to the shared library to display linked assets. To post a shared library on the Web, you publish the movie in which you created the shared library. This procedure posts the shared library to the URL where the movie's SWF file resides. (You can specify another location for the shared library if desired.)

When you play a Flash movie that contains links to shared assets, the movie loads the shared library from its location on the Web and displays the shared assets as specified. The movie downloads the entire shared library file when it reaches the first frame containing a linked asset. (If the movie contains linked assets from more than one shared library, each shared library will be downloaded separately, when the first asset from that shared library occurs.)

If an error occurs in downloading the shared library, the movie will not play. It is recommended that you keep shared libraries as small as possible to minimize downloading time, and that you test movies with linked assets to ensure that downloading functions properly.


 
Defining shared library assets

You use the Symbol Linkage dialog box to assign linkage properties to existing library items in order to specify the items as shared library assets. After you assign linkage properties to shared assets, you must save the movie file in which you defined the shared assets, to make the assets available for linking from other Flash movies.

You also use the Symbol Linkage dialog box to assign an identifier name for a movie clip or a sound file that you want to play using the attachMovie or attachSound method. For information on the attachMovie method, see "Attaching movie clips" in the movie clips chapter of ActionScript Help. For information on the attachSound method, see "Creating sound controls" in the interaction chapter of ActionScript Help.

To define a shared library asset:

1 With a movie file open, choose Window > Library or click the Library button in the Launcher bar (at the bottom right of the application window) to display the Library window if it is not already visible.
2 Do one of the following:
Select an item in the Library window and choose Linkage from the Library Options menu.
Right-click (Windows) or Control-click (Macintosh) an item in the Library window and choose Linkage from the context menu.
3 In the Symbol Linkage Properties dialog box, select Export This Symbol.
4 In the Identifier text field, enter an identifier, or name, for the symbol. (Do not include spaces in the identifier.)
5 Click OK.
6 Save the movie file.


 
About posting a shared library to a URL

A shared library must be posted to a URL as a SWF file in order for the shared assets to appear in movies that link to the assets. When you publish a movie that contains a shared library (that is, the movie in which you defined the shared assets), the shared library is automatically included with the movie's SWF file.

You do not need to specify a URL for a shared library to include the library with the movie's SWF file. However, you can specify a different URL for a shared library file to place the library in another location.

To specify a URL for a shared library:

1 In the Library window, choose Shared Library Properties from the Library Options menu.
2 In the Shared Library Properties dialog box, enter the URL where you want the shared library to be located.
3 Click OK.


 
Linking to assets in a shared library

To link to shared library assets from a Flash movie, you open the shared library and add items from the shared library to the current movie's library.

To create links to shared assets, you open the FLA file for the shared library. It is not necessary to publish the shared library as a SWF file in order to create links to the shared assets.

Note: To preview linked assets when you test a movie, or to display linked assets when you play a published movie, you must first create the SWF file for the shared library. To create the shared library's SWF file, you publish the movie in which you defined the shared library.

To link to shared library assets:

1 With a movie file open, choose File > Open As Shared Library.
2 Select the shared library that you want to open and click Open.
The shared library opens as a Library window in the current movie. Options menu commands and buttons in the shared library window are dimmed, indicating that they are unavailable.
3 To link an asset from the shared library to the current movie, do one of the following:
Drag the asset from the shared library into the library for the current movie.
Drag the asset from the shared library onto the Stage.
The shared asset name appears in the current movie's library. The asset is linked to the current movie as an external file; the asset file is not added to the current movie.