mysql - How to working with mx.rpc.Responder in AS3 -
i trying use library called assql serving operations mysql. in use, saw works method called asyncresponder mx.rpc package available flex applications ... question is, how can use method in conventional as3, or use function solve problem?
package { import com.maclema.mysql.statement; import com.maclema.mysql.connection; import com.maclema.mysql.resultset; import mx.rpc.asyncresponder; import com.maclema.mysql.mysqltoken; import com.maclema.util.resultsutil; import flash.display.movieclip; import flash.events.event; public class crud extends movieclip{ //the mysql connection private var con:connection; public function crud() { oncreationcomplete(); } private function oncreationcomplete():void { con = new connection("localhost", 3306, "root", "", "banricoop-game"); con.addeventlistener(event.connect, handleconnected); con.connect(); } private function handleconnected(event:event):void { getallusers(); } private function getallusers():void { var st:statement = con.createstatement(); var token:mysqltoken = st.executequery("select * users"); token.info = "getallusers"; token.addresponder(new asyncresponder(result, fault, token)); } private function getemployee(userid:int):void { var st:statement = con.createstatement(); st.sql = "select * users id = ?"; st.setnumber(1, userid); var token:mysqltoken = st.executequery(); token.info = "getuser"; token.userid = userid; token.addresponder(new asyncresponder(result, fault, token)); } private function result(data:object, token:object):void { var rs:resultset; if ( token.info == "getallusers" ) { rs = resultset(data); trace("found " + rs.size() + " employees!"); } else if ( token.info == "getuser" ) { rs = resultset(data); if ( rs.next() ) { trace("employee " + token.employeeid + " username '" + rs.getstring("username") + "'"); } else { trace("no such employee id " + token.employeeid); } } } private function fault(info:object, token:object):void { trace(token.info + " error: " + info); } } }
hugs!
you need download flex sdk , add these libraries project:
- /frameworks/libs/framework.swc
- /frameworks/libs/rpc.swc
so, able use in as3 environment.
Comments
Post a Comment