The following procedures describe how to share a simple test function
from a movie called codeLibrary.swf to a movie
called myMovie.swf. We'll create the
codeLibrary.swf movie first:
Create a new Flash document.
Create a new movie clip symbol named
sharedFunctions.
On frame 1 of the sharedFunctions clip, add the
following code:
function test ( ) {
trace("The shared function, test, was called.");
}
Select the sharedFunctions clip in the Library.
From the Library panel, select Options
Linkage.
Select Export This Symbol.
In the Identifier box, type sharedFunctions.
Save the document as codeLibrary.fla.
Use File
Export Movie to create
codeLibrary.swf from
codeLibrary.fla.
Close the codeLibrary.swf and
codeLibrary.fla files.
Now, we'll create the myMovie.swf file,
which will execute the code imported from
codeLibrary.swf:
Create a new Flash document.
Save the new document as myMovie.fla in the same
folder as codeLibrary.fla.
Rename Layer 1 to
sharedCode.
Select File
Open As Shared Library, and choose
codeLibrary.fla. The
codeLibrary.fla Library appears.
Drag an instance of the sharedFunctions clip from
the codeLibrary.fla Library onto the Stage of
frame 1 of myMovie.fla.
Select the instance on stage, then select Modify
Instance.
Name the instance sharedFunctions.
On the main timeline of myMovie.fla, create a
new layer called scripts.
Add a keyframe to the scripts layer at frame 2.
Add a new frame to the sharedCode layer.
On frame 2 of the scripts layer, attach the
following code:
stop( );
sharedFunctions.test( );
Export myMovie.swf.
The following text appears in the Output window: "The shared
function, test, was called."
Note that a shared library is a linked asset, much like a
.gif image is linked to an
.html file. Shared library
.swf files must, therefore, always be uploaded
correctly with the files that use them. To change the location of a
link from an imported symbol to a shared library, follow these steps: