5 Replies Latest reply on Oct 17, 2008 1:50 PM by abeall

    Noobie Help - URLMonitor

    wkolcz Level 1
      I have this code from an example to help me app track if its online or offline:

      private function initApp():void {
      var monitor:URLMonitor = new URLMonitor(new URLRequest(" http://www.bpoprosonline.com"));
      monitor.addEventListener(StatusEvent.STATUS, checkHTTP);
      monitor.start();
      trace(monitor);
      }
      When I traced monitor and got this:
      [SWF] PropertyManager.swf - 1,433,656 bytes after decompression
      [URLMonitor method="GET" url=" http://www.bpoprosonline.com" available="false"]

      Why would it come up as unavailable when the site is live and running?
        • 1. Re: Noobie Help - URLMonitor
          abeall Level 3
          monitor.start();
          trace(monitor);

          That won't work. Flash's network is always asynchronous, so URLMonitor.start will only *start* to check, it will not complete checking before continuing to the next line of code. Until the first check completes it starts out unavailable. You have to add a listener for the status event:

          monitor.start();
          monitor.addEventListener('status',monitorStatus);
          function monitorStatus(evt){
          trace(monitor)
          }
          • 2. Re: Noobie Help - URLMonitor
            wkolcz Level 1
            Tried this and I am getting a 'Access of undefined property monitor.' error and the debug still comes up as available="false".

            private function initApp():void {
            var monitor:URLMonitor = new URLMonitor(new URLRequest(" http://www.bpoprosonline.com"));
            monitor.addEventListener(StatusEvent.STATUS, checkHTTP);
            monitor.pollInterval = 10000;
            monitor.start();
            }

            private function checkHTTP(e:StatusEvent):void {
            trace(monitor);
            }
            • 3. Re: Noobie Help - URLMonitor
              abeall Level 3
              Define monitor outside the functions so it's accessible to both, as in:

              var monitor:URLMonitor;
              private function initApp():void {
              monitor = new URLMonitor(new
              ...

              Or use Event.target, as in:

              private function checkHTTP(e:StatusEvent):void {
              trace(e.target);
              }
              • 4. Re: Noobie Help - URLMonitor
                wkolcz Level 1
                Well, the e.target works to see what the status is. My debug comes up with:

                [SWF] PropertyManager.swf - 1,572,290 bytes after decompression
                [URLMonitor method="GET" url=" http://www.bpoprosonline.com" available="true"]

                How can I then test to see if the available = true?

                I have this condition set, but need to know what can use used as the condition.

                if (e.target) {
                lineStatus.color = "0xFF0000";
                lineStatus.text = "Offline";
                currentStatus = true;
                } else {
                lineStatus.color = "0x00FF00";
                lineStatus.text = "Online";
                currentStatus = false;
                }
                • 5. Re: Noobie Help - URLMonitor
                  abeall Level 3
                  e.target points to the URLMonitor instance, and URLMonitor has a property "available", so just do:

                  if (e.target.available) {
                  lineStatus.color = "0xFF0000";
                  lineStatus.text = "Offline";
                  currentStatus = true;
                  } else {
                  lineStatus.color = "0x00FF00";
                  lineStatus.text = "Online";
                  currentStatus = false;
                  }