3 Replies Latest reply on Mar 11, 2008 4:53 AM by Sunilnairg

    1131:Packages must not be nested

    Sunilnairg Level 1
      Hai all,

      I m working on a Flex Application, in which I have to communicate with the server through TCP Socket. I am using XMLSocketClass. I got a code from help, but I am getting "1131:Packages must not be nested" error whenever I m trying to compile it. Pls tell me the reason for this error.

      ==========================================================================
      XMLSocketExample.as
      ==========================================================================
      package //ERROR// 1131:Packages must not be Nested
      {
      import flash.display.Sprite;
      import flash.events.*;
      import flash.net.XMLSocket;

      public class XMLSocketExample extends Sprite {
      private var hostName:String = "localhost";
      private var port:uint = 8080;
      private var socket:XMLSocket;

      public function XMLSocketExample() {
      socket = new XMLSocket();
      configureListeners(socket);
      socket.connect(hostName, port);
      }
      public function send(data:Object):void {

      socket.send(data);
      }
      private function configureListeners(dispatcher:IEventDispatcher):void {
      dispatcher.addEventListener(Event.CLOSE, closeHandler);
      dispatcher.addEventListener(Event.CONNECT, connectHandler);
      dispatcher.addEventListener(DataEvent.DATA, dataHandler);
      dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
      dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
      dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
      }

      private function closeHandler(event:Event):void {
      trace("closeHandler: " + event);
      }

      private function connectHandler(event:Event):void {
      trace("connectHandler: " + event);
      }

      private function dataHandler(event:DataEvent):void {
      trace("dataHandler: " + event);
      }

      private function ioErrorHandler(event:IOErrorEvent):void {
      trace("ioErrorHandler: " + event);
      }

      private function progressHandler(event:ProgressEvent):void {
      trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
      }

      private function securityErrorHandler(event:SecurityErrorEvent):void {
      trace("securityErrorHandler: " + event);
      }
      }
      }
      ============================================================================
      Flex File
      ============================================================================
      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

      <mx:Script source="XMLSocketExample.as"/>

      <mx:Button x="202" y="140" label="Button" id="sendButton" name="sendButton" />
      <mx:Label x="204" y="110" id="conn_txt" enabled="true"/>

      </mx:Application>