这里就不多说了,应该很容易就可以看懂了!这里没有用TextArea而改用了DataGrid! :-) 刚学会!
import mx.remoting.Service; import mx.services.Log; import mx.rpc.RelayResponder; import mx.rpc.FaultEvent; import mx.rpc.ResultEvent; import mx.remoting.PendingCall; import mx.remoting.debug.NetDebug; import mx.controls.Alert; //加入Alert,以便弹出一个提示信息 //Initialize a Logger mx.remoting.debug.NetDebug.initialize(); // initialize the NCD var myLogger:Log = new Log( Log.DEBUG, "logger1" ); // override the default log handler myLogger.onLog = function( message:String ):Void { trace( "myLogger-->>>"+message ); } //设定全局Service _global.svc = new Service( "http://localhost/amfphp/gateway.php", myLogger, "favorite", null, null); /** * 设定添加按钮的动作 */ append_btn.onRelease = function(){ var pc:PendingCall = svc.append(webname_txt.text,url_txt.text); //呼叫php中的append方法 pc.responder = new RelayResponder(this, "append_Result", "onError"); webname_txt.text = url_txt.text = ""; //清空文本框 } append_Result = function(re:ResultEvent){ //添加按钮响应结果 var id = re.result; if(id != "error"){ mx.controls.Alert.show ("保存:"+id+" ->成功", "Debug Message", Alert.YES, _root, false, "prueba", Alert.OK); refresh_data(); //刷新数据 } else { mx.controls.Alert.show ("技术原因未成保存", "Debug Message", Alert.YES, _root, false, "prueba", Alert.OK); } } /*** * 刷新按钮 */ refresh_btn.onRelease = function(){ favorite_dg.removeAllColumns(); refresh_data(); } /** * 刷新数据 */ function refresh_data(){ var pc:PendingCall = svc.get_data(); pc.responder = new RelayResponder(this, "getData_Result", "onError" ); } /*** * 接收数据显示 */ function getData_Result(re: ResultEvent){ var rs = re.result; favorite_dg.columnNames = ["id_PK", "webname", "url", "timeline"]; favorite_dg.dataProvider = rs; /* 遍历方法 f = rs.length; //数库集大小 for(var i=0; i<f; i++){ favorite_dg.addItem({id_PK:rs.getItemAt(i).id_PK, webname:rs.getItemAt(i).webname, url:rs.getItemAt(i).url, timeline:rs.getItemAt(i).timeline}); } */ } /*** * 出错 :-( */ function onError(rs: FaultEvent){ mx.remoting.debug.NetDebug.trace({level:"None", message:"There was a problem: " + fault.fault.faultstring }); } refresh_data(); //初始数据 stop();
php的服务
<?php /*** * php & flash 收藏夹 之amfphp实现+MySql * * 这里要实现的功能是,用flash来展示和通过php来读写文本来 * 实现一个收藏夹的功能 * * 数据的储存结构 * id_PK,webname,url,timeline */ class favorite { var $dbhost = "localhost"; //数据库地址 var $dbname = "favorite"; //数据库名称 var $dbuser = "root"; //数据库用户名 var $dbpass = ""; //数据库密码 var $conn; //数据库连 function favorite(){ $this->methodTable = array( "get_data" => array( "description" => "Returns data", "access" => |