Parameters and the Default Component User Interface

Fundamentally, a component allows you to manipulate variables within ActionScript without having to delve into the actual ActionScript. For instance, let's say you had some ActionScript that utilizes Flash MX's ability to draw a rectangle with code. Even something as simple as a rectangle has several potential variables. How high is the rectangle? How wide? Where is the rectangle on the stage? What color is it? What is its alpha?

All of these variables can be "hard-coded" within the ActionScript, meaning that the variables are part of the code. The problem with this is that if you want to change these variables, you must go into the code. Finding and editing the code required to generate a rectangle would not be particularly hard. However, components that perform more complex actions like creating a collapsible menu or a game contain code that can be hundreds of lines long.

click to expand
Figure 2.1: The Chapter2_A_Modified.fla sample file is dotted with multiple instances of two separate components.

Furthermore, the code might not all be in one place. For complex resources, finding and editing the variables can be difficult and time-consuming even for experienced programmers-even for the person who wrote the code, particularly if they need to change the variables a long time after they originally wrote it. Components provide a solution to this problem and, in the process, make the code easier to customize, for the programmer and nonprogrammer alike.

In components, each variable is called a parameter. Components make it easier to customize or change the parameters by placing them in a more accessible location: the Component Parameters panel. As you will see in the following example, the Component Parameters panel can take on a wide range of different appearances.

On the CD 

Open Chapter2_A_Start.fla in the Chapter 2 folder on this book's CD. Save the file to your local hard drive as Chapter2_A_Modified.fla.

In this Flash file, the stage is peppered with components. Actually, there are only two components, but there are multiple instances of each of the two components. An instance refers to a particular copy of a symbol in Flash. For example, if you create a movie clip and then drag three copies of that movie clip onto the stage in Flash, you have three instances of that movie clip.

You can manipulate components in much the same way you can manipulate any other symbol in Flash. You can generate multiple instances of a component, and you can duplicate and/or copy a component. If you use multiple instances of a component, you gain the same file-size-saving advantages that other symbols provide.

Go ahead and test the movie to observe what it does (see Figure 2.2). What you will see is a rich animation. If you look carefully, you'll notice two types of animations, both of which utilize simple circles. A series of circles marches end to end, and lines of circles march up, down, left, and right in all different sizes and varied opacities. Each line of marching circles is controlled by a component. Notice, also, the series of circles that zoom in and out of view. Some zoom in, some zoom out. Each zooming circle is also controlled by a component. Close the test movie.

click to expand
Figure 2.2: Multiple copies of two components are used in this example to generate a rich, textured, animated background.




The Hidden Power of Flash Components
The Hidden Power of Flash Components
ISBN: 0782142109
EAN: 2147483647
Year: 2002
Pages: 111

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