Copy link to clipboard
Copied
Hi
I'm trying to create a simple Twitter feed for a Flash website. When I run the flash movie however I get the following messages appear in the Output window:
TypeError: Error #1010: A term is undefined and has no properties.
at Cinema_fla::MainTimeline/processXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
I am using Flash CS6 and the AS3 code for my Twitter feed is shown below:
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=YahooMoviesUK"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void{
var myXML:XML = new XML(e.target.data);
txtTweet1.text = myXML.status[0].text;
txtTweet2.text = myXML.status[1].text;
txtTweet3.text = myXML.status[2].text;
}
I would be grateful if anyone could give me some advice as to why this error is occurring. If you need any more info please let me know.
Thanks
From what I remember, the text of the xml is extracted as a method rather than as a property...
myXML.item.title[0].text(); <----- put () after text
Continue using the trace if things remain errant.
Copy link to clipboard
Copied
Go into your Flash Publish Settings and select the option to Permit Debugging. This can often help by adding a line number to the error message to help narrow down where the problem is.
Beyond that, try using the trace command within the processXML function to see if you can identify which element is undefined.
Note: You should always assign the load complete listener before you initiate the loading process.
Copy link to clipboard
Copied
Thanks for the quick reply! I turned on debugging and the resulting output pointed to the following line in the code:
txtTweet1.text = myXML.status[0].text;
However, I can't see any problem with this? The txtTweet1 is a dynamic text field in my flash application and I've double checked the name which is correct.
I'm a novice user of AS3 so I'm afraid I'm not sure what you mean by: You should always assign the load complete listener before you initiate the loading process.
Copy link to clipboard
Copied
As I already mentioned, trace all of the elements in that line of code to see which one is coming up as undefned.
As for the ordering of things... move the complete listener ahead of the load command...
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
myXMLLoader.load(new URLRequest("https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=Yahoo MoviesUK"));
Copy link to clipboard
Copied
Ok I just tried doing the trace like you said and the output showed me that the twitter XML was using different tag names than I thought. However, after changing the AS code to reflect this (see below) I'm still getting the same error on the same line. I also changed the order of the complete listener and load command:
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
myXMLLoader.load(new URLRequest("https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=YahooMoviesUK"));
function processXML(e:Event):void{
var myXML:XML = new XML(e.target.data);
txtTweet1.text = myXML.item.title[0].text;
txtTweet2.text = myXML.item.title[1].text;
txtTweet3.text = myXML.item.title[2].text;
}
Copy link to clipboard
Copied
From what I remember, the text of the xml is extracted as a method rather than as a property...
myXML.item.title[0].text(); <----- put () after text
Continue using the trace if things remain errant.
Copy link to clipboard
Copied
Thanks so much for all your help! After rearranging the code it now works like a dream.
Thanks again for your speedy responses.
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now