Adobe Air - Check for internet connection

前端 未结 5 1158
遥遥无期
遥遥无期 2021-01-20 17:36

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: D

5条回答
  •  星月不相逢
    2021-01-20 18:21

    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();
            }
    

提交回复
热议问题