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

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

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
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('&apos;').join('\'');
		anim_text += item_title;
		anim_text += "\r\r";
		anim_text_array[i] = item_title;
    }
  }
  else anim_text += 'XML Failed - ';
};

Open in new window


any help would be greatly appreciated.
0
stilliard
Asked:
stilliard
  • 3
  • 2
2 Solutions
 
mitzillaCommented:
You may need to create a setInterval function that will check the feed every 5 seconds or whatever so that it will load the new text.
http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001216.html

Also you may need to add a "cache buster" to handle the loading of the latest info form your xml file.
http://objectmix.com/macromedia-flash/406274-xml-re-loading-using-as2.html
0
 
blue-genieCommented:
what happens if you use the traditional syntax

feed_text.onLoad = function(success) {
 etc.... instead of what you're doing?

0
 
stilliardAuthor Commented:
@mitzilla, setInterval would be a good choice here, although it would require alot of rework for the rest of the code which i did not build unfortunately.
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?
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!

 
stilliardAuthor Commented:
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.
0
 
blue-genieCommented:
i don't understand why you're using an interval,  mitzilla if you don't mind could you explain.
0
 
stilliardAuthor Commented:
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. :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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