3

I'm building an Air app with Adobe Flash CS 5. I need to check if an internet connection is available.

I'm running into this errors:

1172: Definition air.net could not be found. 1046: Type was not found or was not a compile-time constant: URLMonitor.

This is my code:

import air.net.*;

var monitor:URLMonitor;

function checkInternetConnection(e:Event = null):void
{
var url:URLRequest = new URLRequest("http://www.google.com");
url.method = "HEAD";
monitor = new URLMonitor(url);
monitor.pollInterval = 3000;
//
monitor.addEventListener(StatusEvent.STATUS,onConnection);
//
function onConnection(e:Event = null):void
{
trace("onConnection")
}
//
monitor.start();
trace(monitor)
} 

What is missing? Thanks. Uli

Uli
  • 2,625
  • 10
  • 46
  • 71

5 Answers5

10

Hi I have used a following code successfully.

You only have to import: import air.net.URLMonitor;

protected function init():void
        {
            // Center main AIR app window on the screen
            nativeWindow.x = (Capabilities.screenResolutionX - nativeWindow.width) / 2;
            nativeWindow.y = (Capabilities.screenResolutionY - nativeWindow.height) / 2;
            // Detects a general change in network status
            NativeApplication.nativeApplication.addEventListener(Event.NETWORK_CHANGE,onNetworkChange);
        }

        //Checking for network connectivity
        protected function onNetworkChange(e:Event):void
        {
        //  Alert.show("Your Network State changed", "INFO");
            monitor = new URLMonitor(new URLRequest('http://www.adobe.com'));
            monitor.addEventListener(StatusEvent.STATUS, netConnectivity);
            monitor.start();
        }

        protected function netConnectivity(e:StatusEvent):void 
        {
            if(monitor.available)
            {
                Alert.show("Status change. You are connected to the internet", "INFO");
            }
            else
            {
                Alert.show("Status change. You are not connected to the internet", "INFO");
            }

            monitor.stop();
        }
Richk
  • 131
  • 5
7

You need to add the aircore.swc

Go to File->ActionScript Settings

On the Library Path tab, click the + icon (Add New Path) and then click the Flash icon (Browse To SWC).

You then need to browse to the location where Flash CS5 is installed and go to AIK2.5/frameworks/libs/air/ and select the aircore.swc

Pixel Elephant
  • 20,649
  • 9
  • 66
  • 83
  • Done that but now I'm running into this error: `5000: The class 'air.net.URLMonitor' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.` I dragged the **URLMonitor** component from the components inspector into the library. – Uli Mar 13 '12 at 16:22
  • @Uli Did you follow the steps exactly as above? I'm not sure why you would be dragging any components into the library. – Pixel Elephant Mar 13 '12 at 17:51
3

There is an networkChange event in the NetworkInfo class: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetworkInfo.html

snak3
  • 31
  • 1
1

In {Flash_CS5_installation_path}/AIR{air_version}/frameworks/libs/air you can find *.swc files , which you need to include in your application. About 'How to include' read here.

Engineer
  • 47,849
  • 12
  • 88
  • 91
0

Do you have these classes available to your app:

import air.net.*;

i.e. a directory named 'air' sat next to your .fla file.

crooksy88
  • 3,849
  • 1
  • 24
  • 30