cs3mw
08-19-2008, 09:38 AM
Hi,
I keep on getting a number of errors when compiling the following code in actionscript 2.0 (I'm using flash 8).
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.XMLSocket.*;
public class ChatClient extends Sprite {
public var host:String;
public var port:Number;
public var socket:XMLSocket;
public var chatArea:TextField;
public function ChatClient(h:String, p:Number, ca:TextField) {
this.host = h;
this.port = p;
this.chatArea = ca;
}
public function connect():Boolean {
this.socket = new XMLSocket();
this.socket.addListener(Event.CONNECT, socketConnect);
this.socket.addListener(Event.CLOSE, socketClose);
this.socket.addListener(IOErrorEvent.IO_ERROR, socketError);
this.socket.addListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
this.socket.addListener(ProgressEvent.SOCKET_DATA, socketData);
try {
this.socket.connect(this.host, this.port);
}
catch (e:Error) {
trace("Error on connect: " + e);
return false;
}
return true;
}
public function socketConnect(event:Event):Void {
trace("Connected: " + event);
}
public function socketData(event:ProgressEvent):Void {
trace("Receiving data: " + event);
receiveData(this.socket.readUTFBytes(this.socket.bytesAvailable));
}
public function socketClose(event:Event):Void {
trace("Connection closed: " + event);
this.chatArea.appendText("Connection lost." + "n");
}
public function socketError(event:IOErrorEvent):Void {
trace("Socket error: " + event);
}
public function securityError(event:SecurityErrorEvent):Void {
trace("Security error: " + event);
}
public function sendMessage(msg:String):Void {
msg += "n";
try {
this.socket.writeUTFBytes(msg);
this.socket.flush();
trace("Message sent: " + msg);
}
catch(e:Error) {
trace("Error sending data: " + e);
}
}
public function receiveData(msg:String):Void {
trace("Message received: " + msg);
this.chatArea.appendText(msg + "n");
}
}
}
And here is the list of errors....
**Error** Line 1: Syntax error.
package {
**Error** Line 8: Attribute used outside class.
public class ChatClient extends Sprite {
**Error** Line 41: The class or interface 'Event' could not be loaded.
public function socketConnect(event:Event):Void {
**Error** Line 45: The class or interface 'ProgressEvent' could not be loaded.
public function socketData(event:ProgressEvent):Void {
**Error** Line 50: The class or interface 'Event' could not be loaded.
public function socketClose(event:Event):Void {
**Error** Line 55: The class or interface 'IOErrorEvent' could not be loaded.
public function socketError(event:IOErrorEvent):Void {
**Error** Line 59: The class or interface 'SecurityErrorEvent' could not be loaded.
public function securityError(event:SecurityErrorEvent):Void {
**Error** Line 81: ActionScript 2.0 class scripts may only define class or interface constructs.
}
Total ActionScript Errors: 8 Reported Errors: 8
I'm new to actionscript 2.0 so any help would be greatly appreciated.
I keep on getting a number of errors when compiling the following code in actionscript 2.0 (I'm using flash 8).
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.XMLSocket.*;
public class ChatClient extends Sprite {
public var host:String;
public var port:Number;
public var socket:XMLSocket;
public var chatArea:TextField;
public function ChatClient(h:String, p:Number, ca:TextField) {
this.host = h;
this.port = p;
this.chatArea = ca;
}
public function connect():Boolean {
this.socket = new XMLSocket();
this.socket.addListener(Event.CONNECT, socketConnect);
this.socket.addListener(Event.CLOSE, socketClose);
this.socket.addListener(IOErrorEvent.IO_ERROR, socketError);
this.socket.addListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
this.socket.addListener(ProgressEvent.SOCKET_DATA, socketData);
try {
this.socket.connect(this.host, this.port);
}
catch (e:Error) {
trace("Error on connect: " + e);
return false;
}
return true;
}
public function socketConnect(event:Event):Void {
trace("Connected: " + event);
}
public function socketData(event:ProgressEvent):Void {
trace("Receiving data: " + event);
receiveData(this.socket.readUTFBytes(this.socket.bytesAvailable));
}
public function socketClose(event:Event):Void {
trace("Connection closed: " + event);
this.chatArea.appendText("Connection lost." + "n");
}
public function socketError(event:IOErrorEvent):Void {
trace("Socket error: " + event);
}
public function securityError(event:SecurityErrorEvent):Void {
trace("Security error: " + event);
}
public function sendMessage(msg:String):Void {
msg += "n";
try {
this.socket.writeUTFBytes(msg);
this.socket.flush();
trace("Message sent: " + msg);
}
catch(e:Error) {
trace("Error sending data: " + e);
}
}
public function receiveData(msg:String):Void {
trace("Message received: " + msg);
this.chatArea.appendText(msg + "n");
}
}
}
And here is the list of errors....
**Error** Line 1: Syntax error.
package {
**Error** Line 8: Attribute used outside class.
public class ChatClient extends Sprite {
**Error** Line 41: The class or interface 'Event' could not be loaded.
public function socketConnect(event:Event):Void {
**Error** Line 45: The class or interface 'ProgressEvent' could not be loaded.
public function socketData(event:ProgressEvent):Void {
**Error** Line 50: The class or interface 'Event' could not be loaded.
public function socketClose(event:Event):Void {
**Error** Line 55: The class or interface 'IOErrorEvent' could not be loaded.
public function socketError(event:IOErrorEvent):Void {
**Error** Line 59: The class or interface 'SecurityErrorEvent' could not be loaded.
public function securityError(event:SecurityErrorEvent):Void {
**Error** Line 81: ActionScript 2.0 class scripts may only define class or interface constructs.
}
Total ActionScript Errors: 8 Reported Errors: 8
I'm new to actionscript 2.0 so any help would be greatly appreciated.