[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 758
  • Last Modified:

Flash: loadVars() need timeout function.

The following is to check if a domain is up or not.

I need a timeout of say 5 seconds. I am checking a lot of domains at once and don't want to have to wait if a domain is responding slow, also I don't even need to load any variables since I wont use them.

Is there a way to undefine the variables that are loaded or just skip the loading of them alltogether, just see if the domain is alive and quit/timeout?

checkDomainUp = function (stuff)
{
      var myLoadVar = new LoadVars();
      myLoadVar.onData = function(dat)
      {
            if (dat != undefined)
            {
                  //alive code
            }
            else
            {
                                               //down code
            }
      };
      myLoadVar.load(stuff);
};

Also, does anyone know if you can thread loadvars...  have more than one of them running at the same time??

Thank you very much.

Best regards,

Dr34m3r
0
dr34m3rs
Asked:
dr34m3rs
  • 4
  • 4
  • 3
2 Solutions
 
CyanBlueCommented:
Howdy...

Here is a pseudo code for you by using the setInterval()/clearInterval() function...
You might need to tweak the code abit but you get the idea...
Mind you that you cannot really stop the return data from the server even if you delete the myLoadVars instance...  Flash will still receive the data...
Also, you can have more than one running at the same time as long as you have different instance names(myLoadVar, iv0001)...

var myLoadVar = new LoadVars();
iv0001 = setInterval("checkIdle", 1000, myLoadVar);
myLoadVar.iv = iv0001;
myLoadVar.onData = function(dat)
{
      if (dat != undefined)
      {
            //alive code
      }
      else
      {
            //down code
      }
};
myLoadVar.load(stuff);

function checkIdle(_arg)
{
      if (counter0001 < 5)
      {
            counter0001 += 1;
      }
      else
      {
            clearInterval(iv0001);
            delete _arg;
      }
}

CyanBlue
0
 
blue-genieCommented:
Hi, why don't you use the onHTTPStatus method to check?
0
 
dr34m3rsAuthor Commented:
Wow, great idea didn't know it existed!

So basically onHTTPStatus returns an HTTP response code?

Can you give an example? Can't find any reasonable explanations... also does it have a timeout? If so what is the default?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
blue-genieCommented:
have a look in the help file, it's there with all the codes.
and i'm sure there's an example there as well.
0
 
dr34m3rsAuthor Commented:
CyanBlue, do you know how much data loadvars can handle? I don't wanna be downloading megs of data by mistake =D heh....

Also thanks for the timer, I'll check it out when I wake up.
0
 
CyanBlueCommented:
Thanks, blue-genie...
onHTTPStatus...  Never knew what that was all about...  That's what happens if you live in FMXville...  :D

dr34m3rs...  
As far as I know of, you get all that is provided via HTTP pipe...  There is no limit Flash will try to download the data...  Of course, that might eventually crash the Flash if there is more than Flash can handle...
What are you trying to download???

CyanBlue
0
 
dr34m3rsAuthor Commented:
Hey, I'm not trying to download anything actually. All I want to do is know if the domain is up or not, and I think the httpstatus will work great for that as it only checks to see what the HTTP code is. Very handy for what I'm doing. Along with your timer code I should be good to go!!

I'm going to split up the points here as all my questions were answered.

To be fair 250 for each, the onHTTPStatus was a great find, and the counter and answer for how much flash can handle via loadvars was uber too!

Thanks alot for your help CyanBlue and blue-genie (stay blue!! cuz being blue is cooool....)

Dr34m3r
0
 
CyanBlueCommented:
Cool...  Love the blue!!!  :)

CyanBlue
0
 
blue-genieCommented:
blue rocks!!! and hey, i like FMXville -nice and comfortable with no surprises.
0
 
CyanBlueCommented:
Very true...  ;)
0
 
dr34m3rsAuthor Commented:
<3
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now