Flex Mobile 应用程序是基于视图的。而且我正在使用 Adobe Cirrus(我假设它对于任何 FMS netConnection 都相同) 有谁知道如何在 flex 移动应用程序中的视图之间维护持久的 netConnection?
编辑:尝试更清楚地解释我需要什么...
非常简单,我正在连接到 cirrus
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, cirrusStatusHandler);
netConnection.connect(CirrusAddress + "/" + DeveloperKey);
然后我有这个根据连接状态触发某些功能,
protected function cirrusStatusHandler(event:NetStatusEvent):void
switch (event.info.code)
{
case "NetConnection.Connect.Closed" :
trace(event.info.code);
break;
case "NetConnection.Connect.Rejected" :
trace(event.info.code);
break;
case "NetConnection.Connect.Failed" :
trace(event.info.code);
break;
case "NetConnection.Connect.Success" :
trace(event.info.code);
break;
case "NetGroup.Connect.Success" :
trace(event.info.code);
break;
case "NetGroup.Posting.Notify" :
trace(event.info.code);
break;
case "NetGroup.Neighbor.Connect" :
trace(event.info.code);
break;
case "NetGroup.Neighbor.Disconnect" :
trace(event.info.code);
break;
case "NetGroup.SendTo.Notify" :
trace(event.info.code);
break;
case "NetStream.Connect.Success" :
trace(event.info.code);
break;
case "NetStream.Publish.Start" :
trace(event.info.code);
break;
case "NetStream.Play.Start" :
trace(event.info.code);
break;
case "NetStream.Play.Failed" :
trace(event.info.code);
break;
case "NetStream.Play.Stop" :
trace(event.info.code);
break;
case "NetStream.Connect.Closed" :
trace(event.info.code);
break;
case "NetStream.Play.UnpublishNotify" :
trace(event.info.code);
break;
case "NetStream.Unpublish.Success" :
trace(event.info.code);
break;
}
}
我希望能够trace(netConnection.nearID)
在这个视图上,转到另一个视图trace(netConnection.nearID)
并获得相同的结果。并且能够拥有cirrusStatusHandler()
像我上面那样的功能来监听卷云事件。netConnection.close()
如果我想能够关闭连接,那么可以在另一个视图上做。
头脑风暴的想法我认为我可以做什么:
我在想我也许可以在主 ViewNavigatorApplication mxml 文件上设置连接,但是我有很多事情要做,并且基于 netConnection 状态事件被触发,似乎处理每个 mxml 文件中的所有内容可能真的很复杂意见。
也许我可以在 ViewNavigatorApplication mxml 文件中声明 netCon 变量,然后将事件侦听器添加到每个视图上的这些变量?
但我不熟悉访问 mainViewNavigatorApplication mxml 文件中存在的变量
我只需要能够建立一次连接,然后它会一直保持到我打电话netConnection.close()
有任何想法吗?这可能吗?简单的?真的很复杂吗?
我想我可以在不需要 netConnection 的地方使用单独的视图,而只是让这个特定的视图在需要保持 netCon 的视图中使用“状态”。使用状态似乎很愚蠢,因为这是一个基于视图的应用程序。
编辑:@Flextras 答案:
更新:
这是我没有任何错误的编译(直到我调试然后我得到一个崩溃病态解释)
这是我把它放在那里的主要 ViewNavigatorApplication 文件 MYAPP.mxml:
public static var netConnection:NetConnection;
public static var groupspec:GroupSpecifier;
public static var netGroup:NetGroup;
views.HomeView.netConnection = netConnection;
views.ProfileView.netConnection = netConnection;
views.HomeView.groupspec = groupspec;
views.ProfileView.groupspec = groupspec;
views.HomeView.netGroup = netGroup;
views.ProfileView.netGroup = netGroup;
然后在我的视图包中.. ProfileView.mxml:
public static var netConnection:NetConnection;
public static var groupspec:GroupSpecifier;
public static var netGroup:NetGroup;
在我的主页视图中也是如此
但是当我尝试打电话时出现空错误
trace(netConnection.nearID)
在 profileView 的 crationComplete 函数中(在 homeView 之后),看看它是否仍然具有相同的 netConnection,然后应该能够获得相同的 nearID