Flylib.com

Books Software

 
 
 

Conclusion

Conclusion

Components free you from concern with how you are going to implement the advanced functionality for a project. Furthermore, using components allows you to keep your projects from getting out of hand. These in turn free you up to do things like focus more on generating effective designs, creating compelling content, and maybe even meeting your deadlines with time to spare (cue laugh track).

While we will be looking at how to create components later, in Chapters 10 and 11, the majority of this book is about how to use components. We go step-by-step through the process of using many different types of components. Whether you are a beginner or an advanced Flash user , learning how to grab the power of components can be very worthwhile. If there is a component available that performs the functionality you need, then-as the saying goes- there's usually no point in reinventing the wheel.

In the next chapter, we will look at the basics of using components. While components have some similarities to plug-ins or macros, components have their own set of characteristics-some of them are even a bit on the quirky side. However, a little hands-on experience with components will help you to see their incredible potential.


Chapter 2: Using Components 101

Overview

Macromedia has constructed Flash MX with a few little features that can easily trip up the uninitiated. In addition, many of the same aspects that make components versatile and powerful can also make them slightly confusing to work. If you know what to look for and what to watch out for, components can be extremely valuable resources.

The best way of overcoming these minor hurdles is to simply start working with components. In this chapter, you will work with a relatively simple component that utilizes the default component user interface for the Component Parameters panel, exploring some of the advantages and disadvantages (mostly disadvantages) of the default UI. I'll also explain the parameters you'll encounter and their types.

Most of this book's components use custom user interfaces. However, components available for free frequently utilize the default UI. In addition to learning the basics of components, working with the default UI will help you appreciate the value of good custom UIs.

  • The default component UI

  • Understanding parameter types and value types

  • Experimenting with values


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.