Expand my Community achievements bar.

1131:Packages must not be nested

Avatar

Level 2
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>
3 Replies

Avatar

Level 1
I believe you cannot use a package/class in mx:Script source.
The system embeds your code in an existing class.

Avatar

Level 1
I believe you cannot use a package/class in mx:Script source.
The system embeds your code in an existing class.

Avatar

Level 2
Hi, Thanks for your help. I added the follwoing code in my
Flex Application.

<mx:Script>

<![CDATA[

private var aa:<ClassName> = new <ClassName>();

]]>

</mx:Script>



Thanks. No I am facing one more problem. I can't receive any
reply messages from the server, when I am trying to get some
responses through TCP Socket using XMLSocket Class.
addEventListener(DataEvent.DATA, dataHandler) is not working.. I
have posted the problem in the forum. Can u pls go through that??



Thanks in advance,



Sunil NaIR