All,
I was wondering if it is possible in Flash to load from two different url’s at the same time.
Specifically, I have one call to a page using sendAndLoad which takes quite a while to return the information. I would like it so that users do not have to wait for this to finish before executing other loading events (which should be much quicker).
One of the caveats (or at least in my attempts it was) is that I only want to call the first (long) url once.
I looked around for a way to just create my own thread and everything I saw suggested that currently this is not a possibility. I saw several posts suggesting using setInterval instead, and after reading the doc page on it I thought I would be able to get it to work.
Unfortunately, with setInterval I have the following problems (see code below for context):
-
If I put a clearInterval call in getData() anywhere besides the responseXML.onLoad event, it seems to kill the sendAndLoad that was being executed.
-
If I don’t put a clearInterval call (duh) or if I put it in the responseXML.onLoad event, it calls the interval function too many times.
I have included the actionscript below. It would be required to have two url’s to hit, one that is FAST and one that is SLOW to test this.
Any help is greatly appreciated!
Will
var pageURL:String = "[http://zzz/SLOW.aspx?random](http://zzz/SLOW.aspx?random)=" +Math.random();
var requestXML:XML ;
var responseXML:XML ;
var requestNumber:Number = 1;
var intervalID ;
function getData() {
trace("getData()");
requestXML = new XML();
requestXML.ignoreWhite = true;
responseXML = new XML();
responseXML.ignoreWhite = true;
responseXML.onLoad = function(success) {
trace("responseXML = " +responseXML);
}
resultXML.sendAndLoad(pageURL, responseXML);
clearInterval(intervalID);
}
function getInfo() {
var pageURL:String = "[http://zzz/FAST.aspx?random](http://zzz/FAST.aspx?random)=" +Math.random();
var infoXML:XML = new XML();
infoXML.ignoreWhite = true;
infoXML.onLoad = function(sucess) {
trace("infoXML(" +requestNumber++ +") = " +infoXML);
}
infoXML.load(pageURL);
}
var testListener:Object = new Object();
testListener.click = function() {
getInfo();
}
test_btn.addEventListener("click", testListener);
intervalID = setInterval(getData, 1000);