Shared Library Items

 < Day Day Up > 

The whole lidea of storing items in your Library is that they're only stored once, regardless of how many times they're used in a movie. However, an item in one movie's Library isn't automatically recycled if you copy it into another movie. Flash has two (confusingly similar) features to let you share Library items among your movies. There are two ways to do it: runtime sharing and authortime sharing. Runtime sharing involves storing Library items in a single source movie (that gets exported as a .swf). Then, one or more user movies can access the source .swf's items. This way, if the source .swf ever gets updated, the changes will be reflected in all user files. This is just like making an edit to a master symbol, except in this case, multiple movies will reflect the change instead of just multiple instances within one movie.

Authortime sharing is slightly less complex than runtime sharing. You still have one source movie containing Library items. But with authortime sharing, the shared items get recopied into each user file every time you use Test Movie. That is, the user files copy the shared Library item at the time of export. So if a change occurs in the source item, all user files have to be reopened and exported to reflect the change. Plus, each copy of the source adds to the file size of the user files. It's true that authortime sharing is not as modular as runtime sharing, but it's appropriate for larger common elements that you want copied into each user file. One limit of runtime sharing is that the entire shared Library has to fully download before a user file can begin playing. In this way, runtime sharing isn't good for many or large items.

You're about to learn the steps to create and use shared items in the runtime mode. In Hour 23, "Working on Large Projects and in Team Environments," you'll walk through a task involving authortime sharing.

How to Share Library Items at Runtime

Sharing items at runtime involves two basic steps. First, you need to create the Library containing items to be shared. Then, in each file that will use the shared items, you need to establish a link to the source.

Try It Yourself: Prepare Items to Share at Runtime

In this task you'll create a Library containing items that can be shared. Follow these steps:

1.

Create a new file and immediately save it as shared.fla in a folder called RuntimeSharing. Import one bitmapped image (.jpg, .bmp, or .pct, for example). Delete the bitmap on the Stage (don't worry it's still safe in the Library). Also, import one sound file. Finally, create a rectangle and convert it to a symbol (by pressing F8). Then make it a movie clip, name it clip and click OK.

2.

You should now have a Library with three items. Rename the items image, sound, and clip. Generally, the next step is to simply export a .swf containing these three Library items. However, normally when you export a .swf, all unused Library items are excluded so that they don't contribute to the file size. Normally, this is a good thing. The problem is that in this case, you want all the items in the Library to export with the file. Sure, this will add to file size, but you want these assets to be available to many user files. To ensure that each item is included in the .swf export process, you define the linkage properties for each item.

3.

To define the linkage for the sound you imported, find it in the Library, select it, and then select Linkage from the options menu (or right-click). Select the Export for Runtime Sharing check box. This exposes three other required fields: Identifier, AS2.0 Class, and URL. You can accept the default name for Identifier (you should always use something easy to remember). Into the URL field type shared.swf because that's the name for this movie after it is exported. Leave the AS2.0 Class field blank. Figure 20.2 shows the linkage settings you should use.

Figure 20.2. You set a Library item's linkage to Export for runtime sharing. This way, the item will definitely export, even if it's not being used in this file.


4.

Define the linkage for the bitmap and the box movie clip the same way: Click Export for runtime sharing and type shared.swf into the URL field.

5.

Save (by pressing Ctrl+S) and then export this file.

6.

Use Test Movie (by pressing Ctrl+Enter) because the movie is already saved in the right folder. Your source items are now ready to be shared. You can think of this as your shared Library.

Now you can use the shared items in any other movie. Inside the other movies, the items simply need to have the Import for Runtime Sharing check box selected. In the following task, you'll start using the items from the shared Library, and then it should start to make sense.

Try It Yourself: Start Using a Shared Item

In this task you'll create a user file that can access the contents of the shared Library you created in the previous task. Here are the steps:

1.

Create a new file (by pressing Ctrl+N) and select File, Save As. Name the file user1.fla and save it in the RuntimeSharing folder (from the previous task). Now you have to get those shared items into the new movie. You could copy instances from the shared.fla file, but that would involve first creating instances (by dragging from the Library) and then pasting into user.fla. That's not really sharing that's copying. Instead, you want to open shared.fla as a Library. To do that, make sure you're editing user1.fla and that you've closed shared.fla then select File, Import, Open External Library and then select shared.fla. You should see the Library from shared.fla, but notice that it's darkened a bit to represent that it's from another file. You can now use instances from this movie without adding to the file size of the user1.fla file.

2.

Drag items from shared.fla's Library to the Stage of user1.fla. Drag the bitmap onto the Stage. Then open the Library for user1.fla (by pressing Ctrl+L) and notice that the bitmap looks like it was copied into the Library. Try dragging the sound from the shared.fla file's Library to user1.fla's Library. Finally, drag the clip onto the Stage. The file user1.fla now seems to have three items added to its Library (see Figure 20.3). However, these are really just instances pointing to the master version in the file shared.fla.

Figure 20.3. After you bring assets from a shared Library into a user file, they appear to be included in the user file's Library.


3.

Double-click the clip named clip in your user1.fla movie. You should see a dialog box like the one shown in Figure 20.4. Click No. The point is that you can only make edits to the master when you open shared.fla. By the way, you can drag instances from user1.fla's Library onto the Stage, and you're still using instances of the masters saved in shared.fla.

Figure 20.4. Trying to edit a clip set up for runtime sharing causes this dialog box to appear. It basically says that if you want to edit the clip here, it won't be linked anymore. Editing the original is done through the source movie.


4.

Use Test Movie and then look at the file sizes. The shared.swf file should be rather large (it has a bitmap, a sound, and a movie clip). The user1.swf file should be tiny because it only points to the shared.swf file. By the way, it also assumes that shared.swf is adjacent to user1.swf. If you move shared.swf or change its name, user1.swf won't know where to find it.

5.

While you're inside user1.fla, take a look at the linkage settings under each item's linkage properties. You should see Import for Runtime Sharing selected, and you should see the Identifier and URL fields filled in. These settings mean that, when exported, this movie will look in the file shared.swf for items with the identifier listed.

What's the big deal? In the preceding task, you have two files, and one's bigger than the other. So what? First of all, you can repeat the preceding task, but this time you can name the file user2.fla. You can use instances of the same symbols (maybe in different ways), and user2.swf will be tiny, too! Visitors to your site will download shared.swf only once, regardless of whether they view user1.swf or user2.swf or both. In addition, you can change the contents of shared.fla maybe change the bitmap or the clip symbol. Making a change and exporting shared.swf again will enable all your user files (user1.swf, for example) to reflect the change. This is just like how you can change a master symbol, and every instance reflects that change. In the next task, you'll give it a try. (If you want to first repeat the preceding task but name your file user2.fla, you may.)

Try It Yourself: Update Shared Items in a Library

In this task, you'll learn how to update the contents of a shared Library. Follow these steps:

1.

Make sure you've closed all open files and even the Library for shared.fla by selecting File, Close All. Open the source of your shared Library (shared.fla). Take note of what the identifier is for the bitmap by selecting it and selecting Linkage from the Library's Options menu. Delete this bitmap from the Library and import another bitmap that will serve as a replacement.

2.

Access the newly imported bitmap's Symbol Linkage Properties by selecting Linkage in the options menu, select Export for Runtime Sharing, and specify the same identifier as for the old bitmap (probably image).

3.

Save the movie and export a .swf (by pressing Ctrl+Enter).

4.

Double-click any user files you've made (user1.swf, for example). They should now reflect the change.

The preceding task was almost too easy. You simply created a new Library item in the master shared Library file (shared.fla), made sure it would export, and gave it an identifier name that matched the old one. Then, as soon as you exported the .swf, it worked. Basically, each user file doesn't care what's inside the master shared Library; it simply looks for items that match identifier names. For example, if you have a movie clip that contains English language text and swap it with one that contains Spanish, as long as the identifier is the same, it will work fine (it will just appear in a different language).

Although you are probably starting to see how shared Library items can enhance productivity, remember that their other benefit is file size savings. The shared.swf file downloads only once. This might make you want to include larger items (such as sounds and raster graphics). But you should know that when sharing items, the source (shared Library) must download entirely before the user files begin to play. For this reason, you really should use loadMovie or the MovieClipLoader object for larger elements so that you can control and monitor their downloading (as you did in an earlier task this hour). The most appropriate time to use runtime sharing is when you have lots of small items that you expect might need to change periodically for example, a seasonal icon used on several different pages of your website. The icon (set to Export for Runtime Sharing) could change from themes for Halloween to Thanksgiving to New Year's.

Basically, all the upfront work in runtime sharing can be very useful, provided that you use the same styles and assets throughout many files. Runtime sharing also means that all the team members could be given copies of the latest version of shared.swf to use on their computers. In the end, when everything is published, the latest version of shared.swf will be used by everyone. All it takes is a little planning.

     < Day Day Up > 


    Sams Teach Yourself Macromedia Flash 8 in 24 Hours
    Sams Teach Yourself Macromedia Flash 8 in 24 Hours
    ISBN: 0672327546
    EAN: 2147483647
    Year: 2006
    Pages: 235

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net