stilliard
asked on
Actionscript 2 Xml onLoad Event not called!
Hi, im fairly new to actionscript so forgive me if this is a real newb question, but im not getting the onLoad event to work when requesting xml in actionscript 2.
Im building an app which needs to read the first entry from an rss feed for use later on.
Now the rest of the script works fine, however, it works everytime when i view it in flash, but in the browser, it needs me to refresh the page to get it to load. And this is no good as its going to be dynamic content and our client does not want it to cache at all if posible.
the xml file is generated by php, and the file itself loads each time perfectly and doesnt cache itself as the headers i send with it force it to revalidate.
Ive tried to set the feed file also to add a random id code to it, to prevent it caching, but now it doesnt load at all!
Can anyone help with this?
To round up, its only working when its cached the file already, need it to work straight away as its useless to have to reload the page to view it.
the file is workings, but the onload event is not being called the first time the request is sent!
Heres my code
any help would be greatly appreciated.
Im building an app which needs to read the first entry from an rss feed for use later on.
Now the rest of the script works fine, however, it works everytime when i view it in flash, but in the browser, it needs me to refresh the page to get it to load. And this is no good as its going to be dynamic content and our client does not want it to cache at all if posible.
the xml file is generated by php, and the file itself loads each time perfectly and doesnt cache itself as the headers i send with it force it to revalidate.
Ive tried to set the feed file also to add a random id code to it, to prevent it caching, but now it doesnt load at all!
Can anyone help with this?
To round up, its only working when its cached the file already, need it to work straight away as its useless to have to reload the page to view it.
the file is workings, but the onload event is not being called the first time the request is sent!
Heres my code
anim_text = '';
var randomID:Number = Math.round(Math.random()*10000);
var xml_feed_location:String = 'feed2.rss.php?id='+randomID;
var feed_text:XML = new XML();
feed_text.ignoreWhite = true;
feed_text.onLoad = get_feed_text;
feed_text.load(xml_feed_location);
function get_feed_text(success)
{
if (success) {
var channel = feed_text.firstChild.childNodes[0].childNodes;
var item = channel;
for (i=3; i<item.length; i++) {
var item_title:String = item[i].childNodes[0].firstChild.nodeValue;
item_title = item_title.split(''').join('\'');
anim_text += item_title;
anim_text += "\r\r";
anim_text_array[i] = item_title;
}
}
else anim_text += 'XML Failed - ';
};
any help would be greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help,
your idea of using setInterval sparked an idea in my head, which although is not great programming practice in general, it works perfectly in this situation, which as to use a while loop with the xml.load function and to only break once loaded, or after a set "breakpoint" amount of time to avoid breaking the script all-together.
your idea of using setInterval sparked an idea in my head, which although is not great programming practice in general, it works perfectly in this situation, which as to use a while loop with the xml.load function and to only break once loaded, or after a set "breakpoint" amount of time to avoid breaking the script all-together.
i don't understand why you're using an interval, mitzilla if you don't mind could you explain.
ASKER
its a little strange that i had to do this i know, so there must be an issue somewhere previous to this in the script, or how the domain is currently handling these requests, maybe in the htaccess caching.
However, until i can find out what exactly caused this, a while loop which checks / requests the file multiple times untill a successful connection was made.
Bad practice, however, necessary until a more stable fix has been found. :)
However, until i can find out what exactly caused this, a while loop which checks / requests the file multiple times untill a successful connection was made.
Bad practice, however, necessary until a more stable fix has been found. :)
ASKER
So unless theres a way to completely pause the rest of the script while it runs the setInterval, i cannot use it without major reworking another much more advanced users code.
also, yes a more advanced cache buster would be an idea, although the basic one im using (var randomID) should be sufficent for testing purposes at least.
@blue-genie, same result, no change unfortunately.
Added note, i have now found that if i specify a static xml/rss file, it works fine, but the one i need it to run from is php and this causes this issue.
The php file itself is perfectly fine, in fact ive even tried to having the result xml raw in the file for testings and still no luck with the onLoad event. but still the rest of the script works fine.
I have tried setting the php file in htaccess to appear as a rss file but the script did not fall for this and still no luck.
Any other ideas?