Solved

Actionscript 2 Xml onLoad Event not called!

Posted on 2010-08-16
6
879 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

707 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