ACE

Calendar

March 2007
S M T W T F S
  1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Tag Cloud

360Flex actionscript air android apple as3 books conference contest cookbook deeplinking FileReference flash flash builder flash catalyst flashplayer Flash Player flashplayer10 Flex flex4 flexbuilder flickr fotobooth Frameworks google gumbo ImageDropR indexing InsideRIA iphone java localconnection max merapi microsoft mobile pixel bender riatrax SilverLight sqlite swf Thermo update framework updatemanager URLTestr

Categories

Archives

Recent Posts

Recent Comments


« IndyFlex PhotoBrowser Code | Main | Tutorials - Apollo (Community) »

Apollo Online/Offline sample - full source included

By Rich Tretola | March 21, 2007 Print This Post Print This Post
2,098 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.
1
2
3
4
5
6
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:

online.jpg

OFFLINE:

offline.jpg

Download the application

Download source code

Share this Post


Topics: Adobe AIR, Tutorials |

7 Responses to “Apollo Online/Offline sample - full source included”

Critter Says:
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

Rob Says:
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

dave Says:
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.

everythingflex Says:
July 22nd, 2007 at 3:52 pm

Yes, this is old code that was built for Apollo, it will not run under AIR.

john Says:
April 29th, 2008 at 4:24 pm

After a LOT of effort for a c# programmer, a little update

john Says:
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

everythingflex Says:
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/

Comments



You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser
Mobilytics