【问题标题】:AS3 / Flex 3 Staggered Remoting + QueueAS3 / Flex 3 交错远程处理 + 队列
【发布时间】:2011-01-13 08:10:21
【问题描述】:

我正在尝试创建一个将网络连接调用错开一定量的类,以免对我的服务器施加太大压力,因此我的代码中没有十几个网络连接器。 我想要一个可以向其发送调用命令的类,该类将调用添加到队列中,然后大约每隔一秒它会查看队列中是否有任何内容,如果有则调用它。这是我目前所拥有的。

package net
{
 import flash.events.TimerEvent;
 import flash.net.NetConnection;
 import flash.net.Responder;
 import flash.utils.Timer;


 public class Server 
 {
  private static var gateway:String = "http://localhost/gateway.php";
  private static var queue:Vector.<ServerNode>
  private static var nc:NetConnection;
  private static var instance:Server = null;
  private static var res:Responder;
  private var timer:Timer;

  public function Server(e:ServerEnforcer) {
   nc = new NetConnection();
   queue = new Vector.<ServerNode>();
   timer = new Timer(1000);
   timer.addEventListener(TimerEvent.TIMER, execCall);
   timer.start();
  }

  public static function getInstance():Server {
   if (instance == null) {
    instance = new Server(new ServerEnforcer);
   }
   return instance;
  }

  private function execCall(e:Event):void {
   if (queue.length > 0) {
    var node:ServerNode = queue.pop();
    nc.call(node.method, node.res, node.args);
   }
  }

  public function call(method:String, success:Function, failure:Function, ...args):void {
   queue.unshift(new ServerNode(method, success, failure, args));
  }

  private function serverFailure(event:Object):void {
   trace("Server Failure : " + event.description);
  }
 }
}
import flash.net.Responder;

class ServerEnforcer { } 

class ServerNode {
 public var method:String;
 public var success:Function;
 public var failure:Function;
 public var args:Array;
 public var res:Responder

 public function ServerNode(_method:String, _success:Function, _failure:Function, _args:Array) {
  method = _method;
  success = _success;
  failure = _failure;
  res = new Responder(success, failure);
  args = _args;
 }
}

现在当我打电话时

Server.getInstance().call("Fetch.getData", parseAllData, onError)

public function parseAllData(event:Object):void {
    trace("Victory!");
}
public function onError(event:Object):void {
    trace("Error :" + event);
}

绝对没有任何反应。知道为什么这行不通吗?

【问题讨论】:

  • 到底发生了什么?例如,在调试模式下,程序是否连接到服务器,是否只是返回的数据为空,您的应用程序是否运行?至少提供这么多信息。

标签: apache-flex actionscript-3 remoting


【解决方案1】:

您创建了 NetConnection 的实例,但实际上并未启动与服务器的连接。

换句话说,

nc.connect(gateway);

不见了。

有关该课程的更多信息,请参阅NetConnection documentation

【讨论】:

  • 谢谢。这就是问题所在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-30
  • 2012-11-12
  • 2013-09-10
  • 1970-01-01
相关资源
最近更新 更多