Skip to main content
September 21, 2010
Question

Simple Chat application sample code

  • September 21, 2010
  • 1 reply
  • 821 views

Hi Folks,

I was trying out this sample code from the e-book: 'Learning Flash Media Server 3'. I think I have followed everything, from code to setup, for what was mentioned for this code, yet it's not working. Instead of seeing a 'Text Area', 'Input Text' and a 'Button' I am seeing a blank swf and there are no complier errors or anything. I am not sure what is wrong, I hope someone can advise. I am using FMS 3.5 and the following are the code and instructions for the sample code:

Follow these steps to create the application:

1. Open a new Flash file (ActionScript 3.0) and save it as TextSO.fla.

2. Open the Library panel (press Ctrl+L (Windows) or Command+L (Mac OS)) and

drag a TextArea, InputText, and Button component into the Library. Save the file

again.

3. Open a new ActionScript file and save it as TextSO.as.

4. Enter the script in Example 4-3 and resave the file.

package
{
      import fl.controls.TextArea;
      import fl.controls.Button;
      import fl.controls.TextInput;
      import flash.display.Sprite;
      import flash.events.SyncEvent;
      import flash.events.NetStatusEvent;
      import flash.events.MouseEvent;
      import flash.net.SharedObject;
      import flash.net.NetConnection;

      public class TextSO extends Sprite
      {
            private var button:Button;
            private var text_so:SharedObject;
            private var nc:NetConnection;
            private var textArea:TextArea;
            private var textInput:TextInput;
            private var rtmpGo:String;
            private var good:Boolean;
 
            public function TextSO ()
            {
                  //Set up UIs
                  textArea=new TextArea();
                  textArea.setSize (200,300);
                  textArea.move (20,20);
                  addChild (textArea);
                  textInput=new TextInput();
                  textInput.move (20,330);
                  addChild (textInput);
                  button=new Button();
                  button.width=50;
                  button.label="Send";
                  button.move (125,330);
                  button.addEventListener (MouseEvent.CLICK,sendMsg);
                  addChild (button);
                  //rtmpGo = "rtmp://192.168.0.11/basicSO";
                  rtmpGo = "rtmp:/basicSO";
                  nc = new NetConnection( );
                  nc.connect (rtmpGo);
                  nc.addEventListener (NetStatusEvent.NET_STATUS,doSO);
            }
 
       private function doSO (e:NetStatusEvent):void
       {
             good=e.info.code == "NetConnection.Connect.Success";
             if (good)
             {
                   //Set up shared object
                   text_so=SharedObject.getRemote("test",nc.uri,false);
                   text_so.connect (nc);
                   text_so.addEventListener (SyncEvent.SYNC,checkSO);
             }
       }
 
 
       private function checkSO (e:SyncEvent):void
       {
             for (var chng:uint; chng<e.changeList.length; chng++)
             {
                   switch (e.changeList[chng].code)
                   {
                         case "clear" :
                         break;
    
                         case "success" :
                         trace (text_so.data.msg);
                         break;
    
                         case "change" :
                         textArea.appendText (text_so.data.msg + "\n");
                         break;
                     }
              }
       }
 
 
       private function sendMsg (e:MouseEvent):void
       {
             text_so.setProperty ("msg",textInput.text);
             textArea.appendText (textInput.text + "\n");
        }
      }
}

The above are the instructions and code and I have done all of them. I have also placed a folder callded 'basicSO' in the 'Flash Media Server 3.5\applications' folder. I am not sure why it's not working. I hope someone can advise. Thanks.

    This topic has been closed for replies.

    1 reply

    September 21, 2010

    Hi,

    Have you set the Document Class correctly for your TextSO.fla file?, i.e, is the DocumentClass of TextSO.fla pointing to TextSO class? Check the

    File->Actionscript Settings to see what is your Document class. If it is blank then change it to TextSO and save and recompile.

    Thanks,

    Abhishek

    September 21, 2010

    Oh dear, I think I missed that. Yes you are right, it works now. Thanks..