Accessibility

TechNote (Archived)

Using shared libraries

Shared libraries allow multiple movies to share media such as movie clips, graphics, buttons and sounds. For example, a shared library might contain several different buttons and sounds that are used in several different Flash movies. Once the movie containing the shared buttons and sounds has been downloaded, they're accessible to any other movie that references that external media. Since each movie doesn't contain the actual media (buttons and sounds, in this case) and simply references external media, download times can be reduced.

This TechNote explains how to create a shared library, how to link assets contained in a library to another Flash movie, and offers general tips for working with shared libraries. For an overview of shared libraries, see Flash Basics > Using shared libraries in the Using Flash manual.

Contents
Example file download

The files below contain example files for the methods outlined in this TechNote.

Download Windows source file shared_libraries.zip (23K)
Download Macintosh source file shared_libraries.sit (22K)

Note: Flash 5 is required to open these files. For earlier versions of Flash, please follow the steps in this TechNote to create the files. For information about trouble with downloads, refer to Downloading files from the Internet (TechNote 13686).

Create the shared library movie

The first step in using shared libraries is creating the Flash file that will contain the shared assets.

To create a movie containing shared assets:
  1. Open a new Flash file.
  2. Create, or add, a new symbol to be shared (any kind of graphic, movie clip or bitmap symbol) and name itshared_graphic.

    Note: This symbol only needs to reside in the movie's Library, it does not need to be placed on the stage.
  3. Open the Library window by choosing Window > Library.
  4. Select the shared_graphic symbol in the Library and choose Linkage... from the Library's Options menu.
  5. In the Symbol Linkage dialog, select 'Export This Symbol'.

    Enter shared_graphic_id as the identifier string for this symbol. Click OK.



    Note: Any identifier name will do, but it's a good idea to follow the same naming conventions as for other Flash objects. For more information refer to Naming Strategies for Flash (TechNote 14727).
  6. Choose Shared Library Properties from the Library's Options menu.
  7. In the URL text field and enter: shared.swf. Click OK.


    Note: This is the URL where this shared library file will reside (for example, on the server). In this example, the shared library file and the file that we will link to media in the shared library in the next step, will reside in the same web directory. Therefore, no additional path information is required other than the file name.
  8. Save the movie as shared.fla.
  9. Export or publish the movie as shared.swf to the same directory as shared.fla, and closeshared.fla.
Link the shared assets into another movie

After creating the shared library file, the next step is to link the shared assets into another movie. Link to assets in one or more shared libraries in the following ways:

  • Introduce the symbol to the stage directly from the shared library. In this method a shared symbol is first created in an external library, as shown above, and then imported into the host movie in authoring mode. The advantage of this method is that the shared symbol is visible on the stage while authoring the movie.

    Note: When using this method, updates or changes made to assets in a shared library are not seen while authoring or editing the FLA file that links to those assets. Linked assets will appear in the FLA as they were originally introduced into the file. To view authoring-time updates of linked assets, they must be removed, reintroduced, and re-linked. See Viewing updated assets in authoring mode below for instructions.
  • Create a placeholder symbol within the host movie. In this method a placeholder symbol is created within the host movie. The symbol is then linked to an external shared library. The actual linked asset is never seen in authoring mode. One advantage of using this method is that the placeholder acts as a reminder that the item is a linked asset and that the movie must be previewed (in Flash or in a web browser) in order to see the linked media.
Introducing symbols from the Shared Library
  1. Open a new Flash file and save it into the same folder that contains the shared.swf and shared.fla created above. Save it as mainMovie.fla
  2. Choose File > Open as Shared Library, and openshared.fla.

  3. From this shared Library, drag an instance ofshared_graphic onto the stage ofmainMovie.
  4. >Close the shared Library.
  5. Choose Window > Library to open the Library belonging tomainMovie.fla.

    Note that the symbol shared_graphic appears in this Library.

  6. Select theshared_graphic symbol from the Library's symbol list and choose Linkage... from the Library's Options menu. This opens the Symbol Linkage Properties dialog.



    For this example, be sure the fields are identical to those above. The Symbol Linkage dialog shows that this shared asset is imported from the file named shared.swf that was created earlier. Note that the file name is the same one that was specified in the Shared Library Properties dialog of shared.fla (see step 8 above). Click OK.
  7. Save mainMovie.fla.
  8. Test the movie by choosing Control > Test Movie or preview the file in a web browser by choosing File > Publish Preview> Default - (HTML).
Create a placeholder symbol

Instead of importing the shared symbol directly into the host movie, you can also create a "placeholder" symbol in the host movie and then link that placeholder symbol to the imported asset. One advantage to this technique is that the movie's design can be separated from production of the graphics.

To create a placeholder symbol:
  1. Open a new Flash file and save it into the same folder that contains shared.swf and shared.fla. Save it as mainMovie.fla.
  2. Create a new symbol to act as placeholder for the actual linked media and place an instance of the symbol on the stage.

    To assist in design, it may help to create a symbol roughly the size and shape of the linked asset.
  3. Link this new symbol to shared.swf by followingsteps 5-8 of Introducing symbols from the Shared Library in the table above.

    Note: The identifier string assigned to the placeholder symbol in the Symbol Linkage Properties dialog must exactly match that which was assigned to the symbol in the shared library. In this case the identifier string must beshared_graphic_id to match the identifier given to the symbol in shared.fla.
Updating shared library assets

When assets are updated or modified in a shared library, those changes are reflected in any SWF that links to those assets. Changes made to linked assets appear only when the movie is exported as SWF and played either in Test Movie mode or in a web browser.

To update shared assets:
  1. Open the original FLA containing the shared media.
  2. Make the desired changes to the symbols in the movie's library.
  3. Save the FLA.
  4. Republish the file as a SWF, and replace the old SWF on the server.
Viewing updated assets in authoring mode

Changes made to linked assets are NOT seen in the main movie's FLA file in authoring mode. Rather, changes made to linked assets appear only when the movie is exported as SWF and played either in Test Movie mode or in a web browser. However, it is possible to reintroduce the symbol to the main movie and use the Swap Symbol feature to view the changes in authoring mode. If you change the assets and later export them from the shared library movie, the SWF will automatically update. However, you'll need to reintroduce the symbol to the main FLA in order to view the changes there.

To view shared assets in the FLA after updating:
  1. Open the target FLA that links to the shared library.
  2. Locate the symbol in the library you wish to update, and delete the symbol. Each instance of the symbol on the stage will become a small empty square to represent an empty symbol.
  3. Open the original FLA containing the shared media as a Shared Library, by choosing File > Open as Shared Library.
  4. Drag the symbol from the Shared Library into the Library window of your target FLA.
  5. For each instance of the linked symbol in the movie, do the following:
    1. Open the Movie Explorer.
    2. For each instance of the deleted symbol, the instance name is now a vertical line, "|". Select one of these instance names.
    3. Open the Instance Panel by choosing Window > Panels > Instance.
    4. Click the Swap Symbol button located at the bottom of the Instance Panel.
    5. In the Swap Symbol dialog box, select the name of the updated symbol just imported from the shared library. Click OK.
    6. Repeat steps 2- 5 for all symbols in the Movie Explorer named"|".
  6. Since this symbol has been reimported, the Linkage for the symbol must be established again (see step 6, above). Once this is complete, all instances of the updated symbol can be seen in both the FLA file and the SWF file.
Deploying the files to a web server

The file containing the shared assets must be located at the URL specified in the Symbol Linkage Properties of the movie that imports those assets (see step 6, above). In the case ofshared.swf and mainMovie.swf, both files are located in the same folder and the same relationship needs to be preserved when moving the files to a web server. However,shared.swf could have been placed in sub-directory of the main movie directory, as shown below.

In this case, the "Import This Symbol from URL" property for the linked symbol needs to change to reflect the new location of the shared library file. In this case, the URL would be relative:assets/shared.swf.

To re-link shared assets if the path relationship changes:
  1. Open mainMovie.fla.
  2. Select the symbol shared_graphic in the Library and choose Linkage... from the Library's Options menu.
  3. In the text field located beneath the option 'Import This Symbol from URL', change the text from shared.swf toassets/shared.swf, as shown below. Click OK.

  4. Save mainMovie.fla.
  5. Preview the movie by choosing File > Preview in browser

Note: URL naming conventions are used to specify the location linked media. Both relative URLs (for example,assets/shared.swf, or,../assets/shared.swf) and absolute URLs (http://server.com/assets/shared.swf) can be used. It's important to note that some browsers treat relative URLs differently. In many cases it is simpler to use absolute URLs or keep all files in the same folder. A more complete explanation can be found in the related topic Using Relative URLs with Get URL Action (TechNote 4157).

Additional information

There are some additional considerations when using shared assets.

Nested symbols If a shared symbol contains instances of other symbols, each child symbol would need to be exported as a shared asset in order for it act as a shared asset. That is, Flash doesn't recursively export nested symbols as shared assets. For example, a movie clip might use several other symbols for its constituent parts (for example, other movie clip or graphics,). Exporting the main (parent) symbol as a shared asset will not automatically make the child symbols shared, as well. For each child symbol, use the Symbol Linkage Properties dialog box to export it as a shared asset.

Note: The parent symbol will still be sharable without this additional step, but its child symbols will simply be imported into the host movie's library, rather than being referenced as external symbols.

Sound objects The Symbol Linkage Properties dialog is also used to identify sounds for use with the Sound Object. Though similar, the behavior and method for using sounds as linked assets differs from using other symbols as outlined in this document. For more information, refer to "Adding Sound > Using sounds with shared libraries or with Sound objects" in the Using Flash manual and "Creating Interaction with ActionScript > Creating sound controls" in the ActionScript Reference Guide.

Fonts For information on using fonts as shared library items, refer to Using font symbols (TechNote 14786).

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:tn_14767
Browser:Chrome
Internet Explorer
Netscape
Opera
Safari
Firefox

Products Affected: