This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
76
|
Chapter 2: Communication Components
3. Create a new layer, and name it actions. Place this layer above the light_mc layer.
4. Select the first frame of the actions layer, and open the Actions panel (F9). Add
the following code:
app_nc = new NetConnection( );
app_nc.onStatus = function (info) {
trace("app_nc: info.code = " + info.code);
if (this.initLight == null) {
light_mc.connect(this);
this.initLight = true;
}
};
app_nc.connect("rtmp:/test_app");
Here, you create a new NetConnection object that invokes connect( ) on light_mc
when the onStatus( ) event handler is invoked. An internal property named
initLight is used to track whether the light_mc instance’s connect( ) method has
been invoked, as the onStatus( ) handler will likely execute more than once dur-
ing the session of the application. You may need to alter the RTMP URI to
include the full domain name of your FlashCom Server.
5. Save your Flash document and test it. When the Flash movie loads, you should
see the trace( ) message from the app_nc.onStatus( ) handler. If the connection
was successful, the
light_mc instance’s status color should turn green. If the con-
nection failed, the indicator will turn red.
You can continue to modify this example by adding more communication compo-
nents. As you add component instances, you can simplify the code of the onStatus( )
handler by creating an array to store object references to your component instances.
For example, the following code creates a
component_array object that connects three
communication components to the
app_nc connection:
app_nc.onStatus = function (info) {
trace("app_nc: info.code = " + info.code);
if (this.initComponents == null) {
var components_array = [light_mc, bandwidth_mc, av_1_mc];
for (var i in components_array) {
components_array[i].connect(this);
}
this.initComponents = true;
}
};
Conclusion
We’re in only the second chapter of the book, and you’ve already come a long way.
This chapter showed how the FlashCom communication components encapsulate
commonly needed features such as chat, video recording and playback, bandwidth
control, user configuration, and more. These components implement much of a
FlashCom application’s plumbing so you can create basic applications quickly and
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Conclusion
|
77
then enhance them with additional features as needed. We already saw how to build
a simple chat room and add audio and video to it.
Now that you have a basic understanding of creating a simple FlashCom applica-
tion, we’ll explore the technical issues in more detail. In the next chapter, we cover
creating and managing connections. In subsequent chapters, you’ll master addi-
tional topics such as applications and instances, media and data streams, and the
Camera and Microphone classes. You’ve already seen a glimpse of FlashCom’s power
but the journey is just beginning.

Get Programming Flash Communication Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.