Flex Mobile applications are view based. And I'm using Adobe Cirrus (im assuming its the same for any FMS netConnection) Does anyone know how to maintain a persistent netConnection between views in a flex Mobile Application?
edit: to try and explain what i need more clearly...
So real simple here I am connecting to cirrus
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, cirrusStatusHandler);
netConnection.connect(CirrusAddress + "/" + DeveloperKey);
Then I have this to trigger certain functions depending on the status of the connection,
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;
}
}
I want to be able to trace(netConnection.nearID)
on this view, go to another view and trace(netConnection.nearID)
and get the same result. and be able to have a cirrusStatusHandler()
function like I have a above to listen for cirrus events. Then be able to do netConnection.close()
on another view if i wanted to to be able to close the connection.
Brainstorming Ideas what I was thinking I could do:
I was thinking I could maybe set up the connection on the main ViewNavigatorApplication mxml file, but i have so much going on and being triggered based on netConnection status events it seems it might be really complicated to handle everything from that mxml file on each of the views.
Maybe I could declare the netCon vars in the ViewNavigatorApplication mxml file, and just add event listeners to those vars on each view?
But i'm not familiar with accessing vars that exist in the mainViewNavigatorApplication mxml file
I just need to be able to make the connection once, and then it stays persistent until I call netConnection.close()
Any ideas? Is this possible? Simple? Really complicated?
I guess I could use separate views where I dont need the netConnection and just have this particular view use "states" inside the view where the netCon needs to be persistent. It just seems silly be be using states since this is a view based application.
EDIT: @ Flextras Answer:
Updated:
Here's what i've gotten to compile without any errors (until i debug then i get a crash ill explain)
Here is the main ViewNavigatorApplication file MYAPP.mxml I put this in there:
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;
then in my views package.. ProfileView.mxml:
public static var netConnection:NetConnection;
public static var groupspec:GroupSpecifier;
public static var netGroup:NetGroup;
and the same in my Home View
but i'm getting a null error when i try and call
trace(netConnection.nearID)
in the crationComplete function on profileView (which is after homeView) to see if it still has the same netConnection and should then be able to get the same nearID