• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 18. Building the Meeting Application > Constructing the Meeting Room

Constructing the Meeting Room

With the plan in place, follow these steps to construct a meeting room for the Oakbridge Community Centre:

Download the Chapter 18 Exercise File from the book's web site to your desktop.

Create a folder named ch18 in your Flash Communication Server Applications folder. Open your Chapter 18 Exercise folder and copy the chatroom script in the Exercise folder to the folder just created.

The chatroom.as script is what makes the whole thing function. The code in the script is:

// ActionScript Document
// Chat Room Application...

// Joining a Room
// Modifying the RoomList Component to Join a Room without going to a new page (which is the current behaviour of the RoomList Component)

FCRoomListClass.prototype.joinRoom = function()
      var selectedRoom = this.rooms_lb.getSelectedItem().data;

      // Put our selected room data in a global variable
      _global.activeRoom = this.so.data[selectedRoom];
      this.so.data[selectedRoom].users++;   // add a user to the room

      enterRoom();      // call our local function

// Initialization

_global.session = new Object();
_global.ourURL = "rtmp://";      // CHANGE THE URL TO MATCH YOUR FlashComm Server!!!

// Create our NetConnection objects to be used by our two areas

loginArea = new NetConnection();
chatArea = new NetConnection();

// Main Login Handler - called when the login button is clicked
(simplified for the context of our book)

// login = function()
loginBtn.onRelease = function()
      _global.session.username = loginDisp.text;      // get our text
       from our text box - will be used globally
      loginArea.connect( ourURL + "login", session.username );
// make the connection with our username
      gotoAndPlay( "rooms" );      // we're in - so select a room to
      chat in

// Logout Handler -- we're leaving when this button is clicked
// logout = function()
logoutBtn.onRelease = function()
      loginArea.close();      // close our connection
      gotoAndPlay( "login" );

// Leave a Chat Room Handler -- called when we choose to leave a chat room
// leaveRoom = function()
leaveRoomBtn.onRelease = function()
      if( chatArea.isConnected )
            chatArea.close();      // only close the connection if we
            are in a room

      _root.gotoAndPlay( "rooms" );

// called from our "rooms" Frame on the timeline
mainLobby = function()
      if( !loginArea.isConnected )
            loginArea.connect( ourURL + "login", session.username );      // re-connect if we disconnected before

      meetingRooms.connect( loginArea );    // connect our rooms list
      component and display our rooms

      if( activeRoom != undefined )
            _global.activeRoom = undefined;

// Enter Room Handler -- called when a room is selected from our

enterRoom = function()
      loginArea.close();      // close our connect to the login / room
      selection area for now
      chatArea.connect( ourURL + activeRoom.id, session.username ); //
      connect to our chat room!

      _root.gotoAndPlay( "chat" );      // and start chatting away


Essentially, the script—fully commented—is composed of a number of functions designed to dictate what happens when the movie starts and a user enters a particular room. One of the key lines is in the Initialization section of the script. Don't forget to change the RTMP address to match that of your server.

Open Dreamweaver MX 2004. Select File, New to open the New Document dialog box. Select Other from the Categories column and ActionScript Communications document from the list of pages presented. Click Create, and a blank code page will open.


We have seen far too many books that become glorified typing lessons. This is why we have supplied the script in the Exercise folder. You want to build stuff, not spend an inordinate amount of time entering code. Still, study the code. You never know when you might need to write a function that closes a login area.

Enter the following script into the new page:

// ActionScript Communications Document
// This file gets loaded up to the Flash Communications Server area

load( "components.asc" );

application.onConnect = function( client, newUserName )
      gFrameworkFC.getClientGlobals(client).username = newUserName;
// Our FlashCom Server puts the user name in the client's username variable
      application.acceptConnection(client);      // allow the user to

The first line of this script is the one we have been using throughout this section of the book. The next two lines simply put the user's name into a global variable in the client's iteration of the meeting room app and enable the user to move to the various rooms in the facility.

Save the file to the ch18 folder created in Step 2 and name the file main.asc. Quit Dreamweaver MX 2004.

Open Flash MX 2004. When a new blank stage opens, add two layers to the timeline. Name the three layers, from the top layer to the bottom layer:

  • Labels

  • Actions

  • Components

Select Frame 20 in each of the layers and select Insert, Timeline, Frame. This lengthens the movie to 20 frames.


You don't have to select frame 20 in each layer to insert a frame. Click and drag through frame 20 to select the frame in each layer. Press the F5 key to add the frame. This can also be accomplished by selecting Insert, Timeline, Frame.

In the Labels layer, add keyframes at frames 2, 7, and 12. Using the Property Inspector, name the frames as follows:

  • Frame 2: login

  • Frame 7: rooms

  • Frame 12: chat

Select frame 1 of the Actions layer, press the F9 key to open the Actions panel, and enter the following line of code into the input area:

#include "chatroom.as"

Add keyframes at frames 6, 11, and 16 of the actions layer. Add the following script to each key frame:


When finished, your timeline should resemble that shown in Figure 18.1.

Figure 18.1. The meeting room is “wired up” and awaiting placement of the Communications Components.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint