2.1. Overview of Communication Components
There are 16 components in the communication components set. Like all Macromedia components, each contains several built-in ActionScript methods and properties, and you can change the look-and-feel (or skin ) of each component to suit your particular tastes.
Some developers report difficulty creating custom skins (it may involve writing extra drawing code, changing hard-to-find assets, or dealing with components that implement the skinning API only partially). Search the FlashCoders archive or Wiki at http://chattyfig.figleaf.com for some of the discussion.
Chafic Kazoun wrote the following guide to skinning the Flash MX 2004 Components:
You can use the communication components to quickly set up a proof-of-concept FlashCom application that connects one or more users to an application instance and enables live real-time interactivity between the participants . Many of the components can publish audio/video streams to a FlashCom application, while others focus on text or data sharing.
After you have installed the communication components, you can view the components in Flash:
If you just installed the components and Flash was running, quit and restart Flash.
Open the Components panel by choosing Window Development Panels Components.
You will likely find that most of these components have limited appeal for final production-quality Flash movies that you'll make available on a public web site.
|
The components are summarized briefly in Table 2-1. After describing each of the components, we'll show you how to create some simple FlashCom applications using them.
Component name | Description | Notes |
---|---|---|
AudioConference | Enables two or more users to communicate with each other | Nests CheckBox, ListBox, PushButton, and ScrollBar |
AVPresence | Allows a user to send an audio and/or video stream to other users | Nests no other components; see VideoConference and SetBandwidth |
Chat | Creates a text-based messaging interface for a Flash movie | Nests PushButton and ScrollBar; see UserColor |
ConnectionLight | Displays a colored circle indicating the connection status | Nests no other components; see SimpleConnect |
Cursor | Displays the positions and login names of users' cursors | Nests no other components; see UserColor |
PeopleList | Displays the names of all users connected to a FlashCom application | Nests ListBox and ScrollBar |
PresentationSWF | Displays a synchronized slideshow under speaker control to multiple users | Nests PushButton |
PresentationText | Displays synchronized text slides under speaker control to multiple users | Nests ListBox, PushButton, and ScrollBar |
RoomList | Enables a developer to create a gateway to other applications running on your FlashCom Server | Nests ListBox, PushButton, and ScrollBar |
SetBandwidth | Allows a user to control how much bandwidth can be used by Camera and Microphone objects | Nests ComboBox, PushButton, and ScrollBar |
SimpleConnect | Establishes the primary connection to a FlashCom application from a Flash movie client | Nests PushButton |
UserColor | Allows each user to choose a color to represent her identity within the Chat and Cursor components | Nests ComboBox and ScrollBar; affects Chat and Cursor |
VideoConference | Creates a Flash client capable of displaying multiple instances of the AVPresence component | Automatically includes AVPresence |
VideoPlayback | Provides a quick user interface to play back recorded streams | Nests no other components |
VideoRecord | Records and publishes audio and video streams from a Flash movie to a FlashCom application | Nests no other components |
Whiteboard | Displays a shared whiteboard with drawing and text tools | Nests no other components |
Every communication component requires one or more Server-Side ActionScript (SSAS) files, which use the .asc extension. These files exist within the scriptlib folder of the installation directory for FlashCom and are automatically installed with Flash Communication Server MX. Fortunately, you can quickly enable communication components (i.e., make them available for use by your client-side applications) by loading the components.asc file into the main.asc document of any FlashCom application. The components.asc file loads other .asc files into the application instance to enable all of the communication components. Alternatively, you can load each component's .asc file individually to minimize the memory requirements of your FlashCom application.
Every communication component requires a client-side and server-side interaction. When you use a communication component instance in a Flash movie (the client), the component makes calls to a server-side component of the same name. For example, if you have a Chat component in your Flash movie, the component automatically creates a class named FCChatClass . When the Chat instance connects to the FlashCom application, the server-side application creates an FCChat class designed to communicate with the client-side FCChatClass instances.
You'll learn more about the component framework in Chapter 14. For the purposes of this chapter and its examples, we'll explore the basic functionality of the component framework with respect to the communication components.
To load the component framework, which enables client-side movies to use the communication components:
Create a directory, such as myApplication , for your FlashCom application in the applications directory of your FlashCom installation.
Use a text editor such as the one in Flash MX Pro 2004 to create a text document containing the following code:
load("components.asc");
Save this document as main.asc , in the directory you created in Step 1.
You can continue to add Server-Side ActionScript code to the main.asc to implement functionality beyond that of the communication components. Later in this chapter, we'll create basic applications that use the code shown in the previous steps.
|
If you edit any of the communication component symbols in Flash MX 2004, you will find several methods that are common to all components.
In the following exercises, we place all ActionScript in frame 1 of the Actions layer of a document. Create a new layer named Actions for the purpose of holding scripts, and place it at the top of the timeline.
To follow along with a sample component, place an instance of the ConnectionLight component onto the Stage of a Flash document, right-click (Windows) or Ctrl-click (Mac) the instance, and choose Edit. Select frame 1 of the Actions layer and open the Actions panel (F9).
The init( ) method prepares, or initializes, each component instance with name and prefix properties as well as other properties specific to the component type. The prefix is a string used to help identify each component instance within the server-side component framework of the FlashCom application. Each instance is assigned a prefix property using the following convention:
class name + "." + instance name + "."
For example, an instance of the ConnectionLight component named connLight_mc using the Properties panel would have the prefix string value:
FCConnectionLightClass.connLight_mc.
Each component instance is also given a name property, which is exactly the same as the _name property of the movie clip instance for that component. If a component instance was not named in the Properties panel, the name property is set to the string value "_DEFAULT_".
The connect( ) method of each communication component establishes a connection for the component instance to the FlashCom application. This method requires one argument: a NetConnection object that has already successfully connected to a FlashCom application. That is, the component piggybacks onto the previously established connection. For a component specified within the list of communication components for a SimpleConnect instance, its connect( ) method is called automatically. See Section 2.6 later in this chapter for details on calling connect( ) manually.
The connect( ) method uses the prefix property established in the init( ) method (discussed earlier) to invoke the server-side connect( ) method for the same component class. The server-side code is invoked from the client with a NetConnection.call( ) method, passing the prefix value and the "connect" method name as a string, along with any other necessary parameters for the communication component. Each component requires its connect( ) method to be called in order to initialize the new component within the FlashCom application.
|
Each communication component's connection to the FlashCom application can be terminated with the close( ) method. This method invokes the server-side close( ) method for the component's class, using the same NetConnection.call( ) methodology discussed for the connect( ) method. Note that the communication component's close( ) method does not invoke the NetConnection.close( ) method from the Flash client; a connection to the FlashCom application is still maintained even though the component instance has closed its connection.
The onUnload( ) method of each communication component simply invokes the same close( ) method discussed in the previous section. The onUnload( ) handler is invoked when a component instance is removed from the Stage of the Flash movie. An instance can be removed by the act of the playhead going to a frame where the instance does not exist or by client-side ActionScript code using the MovieClip.removeMovieClip( ) method.
Many of the communication components, such as AVPresence and PeopleList, contain a setUsername( ) method. This method specifies the user's name as a string and is usually displayed somewhere in the user interface of the component. For example, if an AVPresence component instance named user_1_mc invokes the setUsername( ) method with a string of "Alan", the name appears at the top left of the AVPresence instance when the user begins to stream audio and video. The following syntax demonstrates this functionality:
user_1_mc.setUsername("Alan");