« IndyFlex PhotoBrowser Code | Main | Tutorials - Apollo (Community) »
Apollo Online/Offline sample - full source included
| By Rich Tretola | March 21, 2007 | Print This Post
|
| 726 views |
Here is a nice little example of testing for online and offline within Apollo. It is very basic.
Test it by either hitting the Test Connection button or by pulling your cable on disconnecting your wireless.
Here is what is occurring within the application:
- on creationComplete Shell.shell.addEventListener(Event.NETWORK_CHANGE,onNetworkChange);
- onNetworkChange test the connection. Here is the contents of the test connection function.
-
- var headRequest:URLRequest = new URLRequest();
- headRequest.method = "HEAD";
- headRequest.url = "http://blog.everythingflex.com";
- var response:URLLoader = new URLLoader(headRequest);
- response.addEventListener(HTTPStatusEvent.HTTP_STATUS,statusChanged);
- response.addEventListener(IOErrorEvent.IO_ERROR,error);
-
- when the HTTPStatusEvent.HTTP_STATUS Event is broadcast statusChanged is called
- The statusChanged fuction checks the status code and sets disconnected if code is 0
- if IOErrorEvent.IO_ERROR is broadcast
- we assume the connection is broken
Thats it. There are additional URLLoader events that can be checked but I haven’t included them in this example. Check the documentation for details on these events. Here is the results:
ONLINE:

OFFLINE:

Topics: Adobe AIR, Tutorials |









April 8th, 2007 at 9:27 pm
Thanks for this. I have basically put this code into it’s own class and am calling it like:
var tmpStatus:NetworkStatus = new NetworkStatus(url_tocheck);
trace(tmpStatus.getStatus());
tmpStatus.getStatus() keeps returning a false. It’s as if it is being executed too quickly. is there a way to make sure the initializing of the class fully executes before proceeding to the next line of code?
Crit
April 11th, 2007 at 11:23 am
Very handy, I knew it would be simple to do but it’s nice to know I don’t have to figure it out myself when I come to need it! Thanks mate
Rob
July 22nd, 2007 at 3:28 pm
Ran into problem with this example. Attempted a complete removal of Apollo and a re-install of AIR. Still ran into a compatibility error.
July 22nd, 2007 at 3:52 pm
Yes, this is old code that was built for Apollo, it will not run under AIR.
April 29th, 2008 at 4:24 pm
After a LOT of effort for a c# programmer, a little update
April 29th, 2008 at 4:37 pm
OOPS CAN’T POST THE CODE !
basically import flash.desktop.Native Application;
in the init function replace the shell call with
Native Application.native Application .add Even tListener(Event.NETWORK_CHANGE,o nNetworkChange);
all else should wok fine
April 29th, 2008 at 7:20 pm
Sorry you wasted so much time with an old Apollo sample. Check out my ConnectionManager class in the EverythingFlexAIR swc:
http://blog.everythingflex.com/air-central/everythingflexair1swc/