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.
LVL 6
stilliardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.