Previous Page
Next Page

Tripod >> 3pod Tips & Learning and manuals for educations

Recipe 3.17. Reusing Elements: Creating Symbols

Problem

You want to reuse an element in multiple places, use an element in a special capacity, such as a button, or simply optimize the use of timelines.

Solution

Convert the element to a graphic, button, or movie clip symbol.

Discussion

Architecture is one of the most important considerations in any Flash movie. Architecture refers to the structure and organization of a movie. You should always strive, in Flash, to keep different elements separate from one another. Yet Flash offers a number of different ways to accomplish this goal. You have seen layers and groups in this chapter. But a far more flexible and powerful solution is to use Flash symbols.

Flash symbols are reusable elements that have additional functionalities that vary by type of symbol. Symbols are reusable in that they are stored in a central repository in a movie, called the library. You can access the library by choosing Window Library in any movie. When a library symbol is placed on the stage, it is called an instance. Instances are linked to symbols in-as-much as the symbols are the blueprints for the instances. If you change any part of a symbol, all its instances throughout the movie are updated instantly. An instance can vary from its parent symbol in the values assigned to instance properties, such as scaling, opacity, placement, and a handful of others. In addition, instances have unique identifiers, called instance names. One benefit of symbols' reusability is that they minimize the impact on file size: no matter how many instances of a symbol exist in a movie, the symbol is only downloaded once.

Reusability is only the beginning of the benefit of symbols. Other types of Flash elements, including imported bitmaps, sounds, and video, are stored in the library and may be reusable. But symbols extend the capabilities of Flash. Symbols make possible each of the following:


Motion tweens

Tweens are one approach to automating animation. See Recipe 4.1.


Nested timelines

Although all Flash symbols have their own timelines, Flash movie clip timelines are independent from the parent timeline. This feature enables complex animations and interactivity.


ActionScript events

Events used to trigger ActionScript can be associated with symbols, including pressing and releasing the mouse, key presses, setting focus, loading data, and much more.


Availability to scripts

Thanks to their unique identifiers and Flash's object model, you can dynamically manipulate button and movie clip symbol instances via ActionScript.

The implications of using symbols are too rich and varied to mention here. They form the substance of Chapters 9, 10, 14, and 15.

Flash contains three common types of symbols, as follows:


Graphic symbols

The simplest form of symbol, graphic symbols are like groups that are stored in the library (and hence reusable). In addition, graphic symbols can be used in motion tweens. Though graphic symbols have their own timelines, they are tied to the parent timeline. As a best practice, use graphic symbols only for single-frame, static assets.


Button symbols

These symbols respond and behave like buttons. Specifically, their timelines have four frames, in which you can insert four graphics to represent different button states (Up, Over, Down, and Hit). Buttons also respond to numerous events, including onPress, onRelease, onDragOut, onRollOver, and more, and are often used to trigger user-initiated ActionScript actions.


Movie clip symbols

The most flexible and powerful Flash symbol, movie clips are like Flash movies inside other Flash movies. Their timelines are fully independent of the main timeline, which means you can pause playback in one while the other continues to play, among other things. They have a host of events, and their numerous properties (such as opacity and position) and methods (such as playback controls, dragability, and collision detection) are all exposed to ActionScript.

New Flash developers are often unsure when to use movie clips as opposed to graphic symbols. Movie clips are much more powerful than graphic symbols, and they are generally preferred over graphic symbols. The exception is single-frame assets that you don't intend to manipulate via a script or use to trigger a script. Movie clips require (negligibly) more overhead than graphic symbols, so the latter still have a place in Flash.

To use symbols, you must first create them, and then deploy one or more instances of them on the stage. Flash offers two common ways to create symbols, from scratch and converted from an existing element:

  • To create a symbol from scratch, choose Insert New Symbol. In the Create New Symbol dialog box, name (exp 3pod.com) the symbol, and select its behavior (movie clip, button, or graphic). Symbol editing mode appears, which consists of a blank stage and an empty timeline. Create layers and keyframes, and add text, art, or imported assets as you would on the main stage.

  • To convert an existing element to a symbol, select it, and choose Modify Convert to Symbol. Specify a name (exp 3pod.com) and the behavior in the Convert to Symbol dialog. The symbol is added to the library, and the originally selected element is converted to an instance. You can convert any combination of vector art, text, groups, and bitmap graphics into a symbol.

Symbols are stored in the library. To create an instance of a symbol, so it appears in the movie, drag the symbol from the library to the stage, in the desired layer and keyframe. To create multiple instances of a symbol, you can drag-and-drop as many times as you need, or you can copy and paste the instance.

To edit a symbol, you can double-click its icon in the library or double-click an instance on the stage. Symbol editing mode opens. After you make changes and return to the movie, all instances are also updated.

Symbols that have no instances are not exported with the SWF by default. It is possible to instruct Flash to export unused symbols using linkage settings. Linkage settings allow a symbol to be added to a movie using ActionScript.


See Also

Recipe 4.1, Recipe 9.1, Recipe 8.13

Tripod >> 3pod Botom Tips & Learning and manuals for educations

Previous Page
Next Page

 

bluedot bluedots greydots pinkdots

Tripod >> 3pod Tips & Learning and manuals for educations