Solved

Actionscript 2 Xml onLoad Event not called!

Posted on 2010-08-16
6
865 Views
Last Modified: 2013-11-11
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
Comment
Question by:stilliard
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
mitzilla earned 400 total points
ID: 33445794
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
 
LVL 39

Assisted Solution

by:blue-genie
blue-genie earned 100 total points
ID: 33446040
what happens if you use the traditional syntax

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

0
 
LVL 6

Author Comment

by:stilliard
ID: 33446506
@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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 6

Author Closing Comment

by:stilliard
ID: 33446789
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 33449169
i don't understand why you're using an interval,  mitzilla if you don't mind could you explain.
0
 
LVL 6

Author Comment

by:stilliard
ID: 33449425
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now