hi!
Nachdem ich gerade meine ganzen AS2-Scripts wieder auf AS1 zurückkonvertier, habe ich mir jetzt mal wieder ein Problem eingehandelt, bei dem ich nicht schlau werde.
Folgende "Klasse" (habe ich aus dem o'Reilly ActionScript Buch):
ActionScript:
/*
* SocketController Class extends XMLSocket
* ActionScript 1
* version: 0.1b // Flash 6 version
* descr.: provides services for communicating with a socket server
*
* Methods
* doConnect() - connect to server
* setServer() - set server host:port
* killConnect() - disconnect from server
* send() - send XML to server
*
* Event Handlers
* onConnectFailure()
* onConnectSuccess()
* onServerKillConnect()
* onClientKillConnect()
*/
// set superclass to XMLSocket
SocketController.prototype = new XMLSocket();
// class constructor
function SocketController (host, port) {
this.host = null;
this.port = 0;
if (arguments.length > 1) {
this.setServer(host, port);
}
}
// try to establish connection to server
SocketController.prototype.doConnect = function() {
if (this.host == null || this.port < 1024) {
trace ("Connection attempt aborted: invalid host or port!");
this.onConnectFailure();
return false;
} else {
var connectSuccess = this.connect(this.host, this.port);
}
if (connectSuccess) {
trace ("initial connection succeeded. Awaiting server response ....");
} else {
trace ("initial connection failed");
this.onConnectFailure();
}
};
// set host and port of server
SocketController.prototype.setServer = function(host, port) {
if (typeof host != "string"
|| typeof port != "number"
|| (typeof port =="number" && port < 1024)) {
this.host = null;
this.port = false;
return false;
}
this.host = host;
this.port = port;
};
// callback to respond to the completion of a connection attempt
SocketController.prototype.onConnect = function (success) {
if (success) {
trace ("Connection to: " + this.host + ":" + this.port + " established.");
this.onConnectSuccess();
} else {
trace ("Connection to: " + this.host + ":" + this.port + " could not be established.");
this.onConnectFailure();
}
};
// callback invoked when server kills connection
SocketController.prototype.onClose = function() {
trace ("server has terminated the connection");
this.onServerKillConnect();
};
// close the connection
SocketController.prototype.killConnect = function() {
trace ("Closing connection");
this.close();
this.onClientKillConnect();
};
// send Data to socket
SocketController.prototype.socketSend = function(message) {
this.send(message);
};
und hier meine Aktionen, die ich aus der ersten Fame aufrufe:
ActionScript:
#include "SocketController.as"
var _TEST = false;
var _LiveScore;
var sheight = 600;
var swidth = 800;
var _deep = 1;
var _sst = 35; // declares the top of the framed stage
var _ssb = 600; // declares the bottom of the framed stage
var _ssh = 0; // declares the heigth of the frames stage
// system.useCodepage = true;
// makeStyle();
main();
fscommand("fullscreen", "true");
function main() {
if (TEST) {
getXML = new XML();
getXML.load("test.xml");
trace (myXML);
} else {
getXML = new SocketController();
getXML.setServer("10.1.1.26", 7000);
getXML.doConnect();
getXML.onConnectSuccess = function () {
trace ("Connection established");
}
getXML.socketSend("INIT");
var i:Number = 0;
getXML.onXML = function (scr) {
// trace ("--------------------------- received XML -----------------------------");
if (i==0) {
if (ConnectOK(scr)) {
trace ("Server sent: " + scr);
} else {
trace ("Server did not send OK");
}
} else {
trace ("Server sent XML");
trace (scr);
useXML(scr);
}
i++;
}
}
}
also mein Problem bezieht sich auf das Debuggen des Movies. Wenn ich einen Breakpoint am Anfang des Scripts setze und mich dann durch den Source hantel, komme ich bis zu dieser Zeile im Klassenkonstruktor:
ActionScript:
var connectSuccess = this.connect(this.host, this.port);
Wenn ich die Zeile ausführen lasse, führt Flash das ganze Projekt bis zum Schluss aus und ich kann nicht genau sagen, was er macht... Das ist natürlich ziemlich nervend!
Was mache ich falsch?
mfg
Juro