信号永远不会被注入 - robotlegs2.0

时间:2014-05-16 15:03:13

标签: actionscript-3 robotlegs robot-legs-problem

在app配置文件中,我有一个Signal / Command映射

signalCommandMap.map(DisconnectUserSignal).toCommand(DisconnectUserCommand);

然后, 我有两个连接类:

public class BaseConnection implements IBaseConnection
{ 
   // When I am trying to inject the signal here: 
   [Inject] public var disconnectUserSignal:DisconnectUserSignal; // it is always null

   _netConnection = new NetConnection();
   ... 
}

public class BBConnection extends DefaultConnectionCallback implements IBBConnection
{ 
  // When I am trying to inject the signal here:
  [Inject] public var disconnectUserSignal:DisconnectUserSignal; // it works perfectly fine

  _baseConnection = new BaseConnection(this);
}

是否有任何可能的原因? 谢谢

1 个答案:

答案 0 :(得分:0)

在浏览了robotlegs框架文档之后 - 我找到了答案:

我将_baseConnection更改为一个接口,并将所有内容从BaseConnection的构造函数移动到init方法中,现在我将它注入到我的BBConnection中。

BBConnection现在看起来如何:

[Inject]
public var baseConnection:IBaseConnection;

public function BBConnection() 
{
}

[PostConstruct]
public function init():void
{
   baseConnection.init(this);
}

现在我可以在基础连接中成功注入Disconnect信号。

来源:https://github.com/robotlegs/robotlegs-framework/wiki/common-problems#injected-properties-are-null-in-constructor