Shared libraries in Macromedia Flash allow multiple movies to reference a single media asset such as a graphic, movie clip or sound. During authoring, shared symbols can improve workflow by allowing teams of designers to easily share media. During playback, shared assets download once and can be used by several movies, reducing file size and download time. 

Due to the nature of shared symbols, however, actions cannot be applied to instances of shared buttons. One solution is to place an instance of the button inside an empty movie clip and apply actions to that button instance. This "parent" movie clip symbol is then shared, rather than the button itself. However, this results in the same action being executed for each instance of that shared movie clip. Another solution is to use shared graphics inside a locally created button symbol. Different actions could be attached to separate instances of this button symbol, since it is local to the current movie. This method, however, requires keeping track of multiple imported graphic symbols.

Smart clips, new in Flash 5, provide one way to easily allow different instances of the same shared button symbol to perform different actions. Similar to the first solution mentioned above, a button symbol is "nested" inside another movie clip. Actions applied to the button include ActionScript variables, such as parameters to functions or actions. Clip parameters that correspond to those ActionScript variables are added to the parent movie clip, which is then exported as a shared item. In movies that import this movie clip, it's easy to customize the behavior of each button/clip instance using the Clip Parameters panel.

An example

The steps below explain how to create a shared button whose instances will open different URLs from agetURL()action. The first part involves creating the shared button and assigning clip parameters to its parent clip.

To make the shared button symbol:

1

Open a new movie in Flash and save it as shared.fla.

2 Create a new movie clip symbol (Insert > Symbol) and give the symbol a name like button_parent, for example.
3 Add a button to this movie clip's Timeline, such as one of the buttons from the Buttons common library (Window > Common Libraries > Buttons).
4

Attach the following action to the button instance:

on (release) { getURL (theURL); }

If working in Normal scripting mode, be sure to select the Expression option next to the URL field.

5 Open the Library window (Window > Library) and select the button_parent symbol. Choose Define Clip Parameters from the Library window's Options menu.
6 Click the Add (+) button at the top of the Clip Parameters dialog to add a new name/value parameter pair.
7

Select the Name field by double-clicking it, and entertheURLas the parameter name, as shown below.

Leave the the other fields at their default values.

8 Click OK.
9

Select the button_parent symbol in the Library window again, and choose Linkage from the Options menu.

10

In the Symbol Linkage Properties dialog, select the Export this symbol option and enter a string in the Identifier field.

11 Click OK.
13

Publish (export) the file as shared.swf to the same folder as shared.fla.

12 Save and close shared.fla.

The next step is to import button_parent into a new, host movie and add instances of the clip to the Timeline. The Clip Parameters panel is used to modify the getURL action applied to each button instance.

To import the movie clip and customize the getURL action:

1 Open a new Flash movie and save it as host.fla to the same folder that contains shared.fla and shared.swf.
2

Choose File > Open as Shared Library and open shared.fla. The Library window for that FLA should appear containing the button_parent symbol as well as the actual button (named Grey_button, in this case).

Note: If the Library window does not appear, make sure that shared.fla is not open for editing in the background. If it is, close shared.fla and repeat this step.

3

Drag two or three instances of button_parent (not the button symbol itself) from shared.fla's the Library window to the stage. (See note below about nested shared symbols.)

4 Select one of the movie clip instances and open the Clip Parameters dialog (Window > Panels > Clip Parameters).
5

Double-click the Value field to select it and enter a URL, such as http://www.macromedia.com.

Repeat this step for the other clip instances, entering a different value for theURL.

6

Save the movie to the same directory as shared.fla and shared.swf.

Note: You can save the movie to another directory but you would need to change the Linkage property for the imported button_parent symbol. 

7 Preview and test the movie in a browser (File > Preview). Each button should open a browser window with different URLs.

A note about "nested" shared symbols

When you import a shared symbol that contains other symbols, those "nested" symbols also appear in the host movie's Library window. This is the case even if the nested symbols are not shared themselves. For instance, in the above example, the movie clip named button_parent contains a button named Grey_button. Just the movie clip has been shared and imported, but both the button and its parent movie clip appear in the host movie's Library.

If you attempt to edit the shared movie clip symbol, button_parent, Flash presents you with the following warning:

Shared symbols can only be edited, and remained linked, if changes are made to the symbol in its original movie (shared.fla, in this case.) If you click Yes to the above warning dialog, the shared symbol will be fully imported into the host movie. That is, it will no longer be linked.

However, the same warning does not appear if you attempt to edit Grey_button, a symbol nested inside of the shared symbol button_parent. This is somewhat misleading as nested symbols appear only as placeholders for their linked counterparts. For example, changes made to Grey_button will only appear while authoring the host movie in Flash. During playback, the external Library item is referenced and displayed.

Changing the appearance of the imported button

To change the appearance of the imported button symbol, open shared.fla and make the desired changes to the original button symbol. Re-export the Flash movie as an SWF to its same location.

 

Keywords: tn_15914

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy