[ascoders] Re: Klassen Fehler

  • From: 1stpixel <1stpixel@xxxxxxxxxxxxxxx>
  • To: ascoders@xxxxxxxxxxxxx
  • Date: Wed, 28 Apr 2004 01:05:04 +0200

boah ... es ist einfach zu spät ... :

import Database.Mysql;
MYSQL = new Mysql ("gateway.php", this.MYSQL_Callback);
MYSQL.database = "enteraktiv";
$table = "artikelliste";
//
query_tf.text = "SELECT * FROM " + $table;

query_Listener = new Object();
query_Listener.click = function(eventObject){
        MYSQL.query (query_tf.text);
}
sendQuery_btn.addEventListener("click", query_Listener)

function MYSQL_Callback (_xml:XML) {
        result_tf.text = _xml;
}

und die Klasse:

class Database.Mysql {
        /*
        * Class Vars
        */
        private var __database:String;
        private var __gateway:String;
        private var __logFile:String;
        private var __sendXML:XML;
        private var __replyXML:XML;
        private var __onLoad:Function;
        private var __callback:Function;
        // constructor
        function Mysql (gw, callback:Function) {
                __gateway = gw;
                __callback = callback;
        };
        /*
        * Getter and Setter for __datatbase
        */
        function set database (db:String):Void {
                if (db != undefined) {
                        __database = db;
                } else {
                        trace ("Error: ´Database.Mysql.set__database()´ requires 1 
Argument: [String]!");
                };
        };
        function get database ():String {
                return (__database);
        };
        /*
        * Getter and Setter for __path2PHP
        */
        function set gateway (path:String):Void {
                if (path != undefined) {
                        __gateway = path;
                }else {
                        trace ("Error: ´Database.Mysql.setGateway()´ requires 1 
Argument: [String]!");
                }
        };
        public function get gateway ():String {
                return (__gateway);
        };
        /*
        * main Function
        */
        public function query(qs:String) {
                var mysql = this;
                __sendXML = new XML();
                __sendXML.contentType = "text/xml";
                __replyXML = new XML();
                __sendXML.parseXML("<gateway><query_db>"+ __database +"</query_db><query_str><![CDATA["+ 
qs +"]]></query_str></gateway>");
                __onLoad = function (success) {
                        if (success) {
                                mysql.__logFile += this + "\n";
                                mysql.functionCallback (this);
                        } else {
                                mysql.__logFile = "mysql connection failed.\n";
                                mysql.showLog();
                        };
                };
                __replyXML.onLoad = __onLoad;
                __sendXML.sendAndLoad(gateway, __replyXML);
        };
        private function functionCallback (_xml:XML) {
                __callback (_xml);
        }
        public function set callback (func:Function) {
                __callback = func;
        }
        public function get callback ():Function {
                return __callback;
        }
        /*
        * Custom Debug Functions
        */
        public function showLog():Void {
                trace (__logFile);
        };
        function get logFile():String {
                return (__logFile);
        };
        public function clearLog():Void {
                __logFile = "";
        };
}


... und immer schön den Cache leeren ... wenn man mit Firefox arbeitet muss man das manchmal erzwingen ...


recht schönen Dank Ralf ... das waren ein paar nützliche Tipps ... lade morgen das script auf'n FTP, wo man es dann 'bestaunen' kann ...

heute ist es einfaach zu ... spät ;-)=

1stpixel

1stpixel schrieb:
es verpuff nicht, sondern es kommt einfach nichts an ...
baue ich ein einfaches trace(this) ein, was den xml text ausgeben sollte, kommt einfach null.


> Wenn __onLoad = function (success) aufgerufen wird (asynchron), ist die
__onLoad gehört ja zu __replyXML:XML was dann aufgerufen wird, wenn __replyXML.loaded = true


...

du traust flash aber auch gar nichts zu, was ? ;-)

... aber trotzdem ne gute idee mit der callback funktion ...

hier der aktuelle stand:

class Database.Mysql {
/*
* Class Vars
*/
private var __database:String;
private var __gateway:String;
private var __logFile:String;
private var __sendXML:XML;
private var __replyXML:XML;
private var __onLoad:Function;
private var __callback:Function; // NEU ... ich weiß etwas dirty aber ...
public var diz;
// constructor
function Mysql (gw, callback:Function) {
__callback = callback;
arguments.length == 1 ? gateway (gw) : null;
diz = this;
};
/*
* Getter and Setter for __datatbase
*/
function set database (db:String):Void {
if (db != undefined) {
__database = db;
} else {
trace ("Error: ´Database.Mysql.set__database()´ requires 1 Argument: [String]!");
};
};
function get database ():String {
return (__database);
};
/*
* Getter and Setter for __path2PHP
*/
function set gateway (path:String):Void {
if (path != undefined) {
__gateway = path;
}else {
trace ("Error: ´Database.Mysql.setGateway()´ requires 1 Argument: [String]!");
}
};
public function get gateway ():String {
return (__gateway);
};
/*
* main Function
*/
public function query(qs:String) {
var mysql = this;
__sendXML = new XML();
__sendXML.contentType = "text/xml";
__replyXML = new XML();
__sendXML.parseXML("<mxcomm><query_db>"+ __database +"</query_db><query_str><![CDATA["+ qs +"]]></query_str></mxcomm>");
__onLoad = function (success) {
if (success) {
trace (diz);
mysql.__logFile += this + "\n";
mysql.functionCallback (this);
} else {
mysql.__logFile = "mysql connection failed.\n";
mysql.showLog();
};
};
__replyXML.onLoad = __onLoad;
__sendXML.sendAndLoad(gateway, __replyXML);
};
private function functionCallback (_xml:XML) {
__callback (_xml);
}
public function set callback (func:Function) {
__callback = func;
}
public function get callback ():Function {
return __callback;
}
/*
* Custom Debug Functions
*/
public function showLog():Void {
trace (__logFile);
};
function get logFile():String {
return (__logFile);
};
public function clearLog():Void {
__logFile = "";
};
}


1stpixel

Ralf Siegel schrieb:


leider weiß ich aber immer noch nicht wieso onLoad zwar success hat, aber nischt ankommt ?!



mhm, das return(this) verpufft.


Wenn __onLoad = function (success) aufgerufen wird (asynchron), ist die query() Methode schon längst durch, d.h. die gibt immer undefined (nischt) zurück.

Du müsstest sowas wie im else-Zweig machen, z.B.

if (success) {
                mysql.__logFile += this + "\n";
                mysql.callback(this)

r.


------------------------------------------------------------- Ralf Siegel - Freelance Developer Recommended Listening: Isobell Campell - Amorino (Snowstorm) http://www.isobelcampbell.com -------------------------------------------------------------

------------------------------------------------------
Archiv   : //www.freelists.org/archives/ascoders/
Optionen : //www.freelists.org/list/ascoders
------------------------------------------------------


------------------------------------------------------ Archiv : //www.freelists.org/archives/ascoders/ Optionen : //www.freelists.org/list/ascoders ------------------------------------------------------


------------------------------------------------------ Archiv : //www.freelists.org/archives/ascoders/ Optionen : //www.freelists.org/list/ascoders ------------------------------------------------------

Other related posts: