Chapter 13. Building Communication Components


Chapter 13. Building Communication Components

The preceding chapters have introduced the classes that form the foundation of every communication application. The core communication classes in client-side Flash ActionScript are Video , Camera , Microphone , NetStream , NetConnection , and SharedObject . In FlashCom Server-Side ActionScript, the core classes are Application , Client , SharedObject , Stream , and NetConnection . Describing and demonstrating how to work with each class has taken up more than half of this book for good reason: facility with the core communication objects is a necessity for building applications. The preceding chapters included many small test and demonstration programs and, if you have been reading through them sequentially, you may be wondering how to turn the many examples you've seen into full-featured applications. The remainder of this book is devoted to providing you with the information and examples you need to build useful, robust, secure, and scalable applications.

This chapter describes the first and arguably most important step in building full-fledged applications. It introduces how to design and build custom communication components. Building communication components makes it possible to partition applications into well-defined building blocks that can be built and tested separately and then assembled to make a variety of applications. One advantage of composing an application out of communication components is that many components can manage their own stream and shared object resources without the rest of the application having to manipulate them. Similarly, the code and logic for communication functions such as text chat, video conferencing, shared text areas, and people lists can be encapsulated within each component. In this respect, communication components often resemble miniature applicationseach may make use of multiple user interface components, employ client- and server-side code, and manage its own data. Since each communication component is relatively self-contained, adding a component to an application is relatively simple.

If you've looked in Flash's Library panel, in the server's scriptlib folder of Macromedia's communication components and component framework, or at Macromedia's v1 or v2 user interface component sets, you may feel that components are complex and time-consuming to understand and build. In fact, they are not so difficult to make. The communication components in this chapter do not rely on Macromedia's communication component framework or any of Macromedia's communication components. Using, modifying, and creating your own components within Macromedia's framework is described in the next chapter.

This chapter begins by building a simple people list component that shows who is connected to an application instance. It isn't much more than a visible list of users generated from the contents of a shared object. Then, we'll extend the simple people list to manage its own shared object, work with a separate user status component, and display connection status icons beside each user's name . Other components, including a text chat, shared text, video conference, video window, and people grid are also described. Some of the components are designed to work together or be used independently.

The word "component" has many different meanings, so it is important to explain its use in this chapter. In general, a component is software that has been built according to a well-defined standard or component model . The component model may include a set of interfaces, an event model, and a set of base classes from which you can derive your own components. If the component conforms to the component model, it can be incorporated into applications without being modified.

Flash provides a component model (a.k.a. a component framework ) and comes with a number of ready-made components. The most often used are the UI components such as the Button, TextInput, and List components. At the most fundamental level, a Flash component is a movie clip that can be imported into a Flash movie's Library and used with little or no configuration. A component movie clip often contains assets such as imported image, video, and sound files; other Flash symbols; and ActionScript code. The Flash component model has evolved from support for so-called Smart Clips in Flash 5, through the v1 component architecture of Flash MX, to the v2 component architecture introduced in Flash MX 2004. Flash components that are imported into a Library can be dragged to the Stage, resized, and customized using the Properties panel, Component Inspector, or ActionScript without having to alter the internal elements of the component itself.

Flash components can be used to build larger and more complex Flash components. For example, a text chat component will often contain TextArea, TextLabel, and Button components. However, a text chat component is also a communication component. It requires a connection to a FlashCom Server and may include server-side scripts as an essential part. This chapter is about building communication components, but for brevity we often refer to communication components simply as components .

Unlike the v1 and v2 component architectures created by Macromedia, there is no special way to package the server-side script (and server-side media files) of a communication component. Installing scripts on the server requires copying ActionScript files to the server and, often, editing the main.asc file. The Macromedia communication components' architecture, described in the next chapter, does provide important elements of a server-side component model.

So, for the purposes of this chapter, communication components are Flash components coupled with server-side scripts that work together. The components presented in this chapter all use the v2 component set and message handling system introduced in Flash MX 2004.

Most of the code examples in the remainder of the book use ActionScript 2.0. In order to compile these examples, set the ActionScript version to ActionScript 2.0 under File Publish Settings Flash. Many examples require the components that are included only in Flash Pro and will therefore not compile in the standard edition of Flash MX 2004.


The documentation included with Flash update 7.2 has improved coverage of the v2 component architecture, but it is still incomplete in some respects. This chapter contains some helpful information on building v2 components; however, building components is a large topic so you may wish to refer to some of the following references:

Macromedia's LiveDocs often includes additional comments, notes, and examples; see the section on using components:

http://livedocs.macromedia.com/flash/mx2004/index.html

The Macromedia Developer Center section on Flash Components page provides articles and sample source code for most components:

http://www.macromedia.com/devnet/mx/flash/components.html

The source code for the Flash MX 2004 components can be found at a path similar to:

C:\Program Files\Macromedia\Flash MX 2004\en\First Run\Classes\mx

At UltraShock 's site, see the Tutorials/Flash MX 2004 section:

http://ultrashock.com

Nigel Pegg wrote many of the components and has posted useful information about using and customizing them in his blog at:

http://www.markme.com/nigel

See Joey Lott's article on creating components here:

http://www.person13.com/articles/components/creatingcomponents.html



Programming Flash Communication Server
Programming Flash Communication Server
ISBN: 0596005040
EAN: 2147483647
Year: 2003
Pages: 203

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