For those of you trying to create a twitter vs flash mash-up, hopefully this will help.
- Download an svn client, such as TortoiseSVN (http://tortoisesvn.net/downloads)
- Using your client, download the latest .as (AS3) files from http://twitterscript.googlecode.com/svn/trunk
- Create a new Flash AS3 file
- Create a new ‘Document class’, named TwitterUserFeed.as, and assign it to your newly created Flash file
- Add the following code to your document class (updating your package name and TWITTER_USER accordingly)
- Publish the movie and watch the ‘output’ panel
- View the Twitter.as file to help you extend this example
package com.trevorboyle.twitter
{
import flash.display.Sprite;
import twitter.api.data.TwitterStatus;
import twitter.api.Twitter;
import twitter.api.TwitterSearch;
import twitter.api.events.TwitterEvent;
/**
* ...
* @author Trevor Boyle
*/
public class TwitterUserFeed extends Sprite
{
private static const TWITTER_USER:String = "stephenfry";
private var _twitter:Twitter;
private var _twitterSearch:TwitterSearch;
public function TwitterUserFeed()
{
_twitter = new Twitter();
_twitterSearch = new TwitterSearch();
_twitter.loadUserTimeline(TWITTER_USER)
_twitter.addEventListener(TwitterEvent.ON_USER_TIMELINE_RESULT, userTimelineResult)
}
private function userTimelineResult(e:TwitterEvent):void {
var twitterStatus:TwitterStatus;
for (var i in e.data) {
twitterStatus = e.data[i]
trace(twitterStatus.text)
}
}
}
}
Do you happen to have a sample fla file? I get an error that says “1046: Type was not found or was not a compile-time constant: TwitterEvent.”
Hello Dan, the fla is completely empty, apart from the reference to the Document class, so unfortunately not much use to you.
It looks as though your TwitterEvent class isn’t importing correctly. Is your .fla in the same folder as the ‘twitter’ folder that you downloaded from google code?
got it working. thanks. had to move it up one folder.
hi there,
how do you get around the security sandbox issue once you publish to a server? this example works great btw,
josh
Hi JoshK, I briefly touch upon it in my ‘Twittersphere’ post http://blog.trevorboyle.com/?p=63
The easiest way to achieve this is to use a PHP proxy script. You make a call to a proxy script on your server which then reads in an xml feed from twitter. Your flash app then thinks the xml is coming from your own sever… which in a way, it now is.
You can grab the proxy script that I started with from here http://woveninteractive.net/?p=45
Good Luck :)
I have setup the package and the updates load into the Output window but I cannot pull the twitterStatus.text into a textfield in the fla. Does anyone have a suggestion on how to load the output data into a textfield?
Pingback: Johannes Luderschmidt’s Blog » Blog Archive » Twitter AS3 library TwitterScript Flex Example
Flash says:
Error opening URL ‘http://twitter.com/statuses/user_timeline/stephenfry.xml’
Error #2032: Stream Error. URL: http://twitter.com/statuses/user_timeline/stephenfry.xml
and opening the XML in a browser window, regardless of TWITTER_USER value, results in XML which gives error:
Rate limit exceeded. Clients may not make more than 150 requests per hour.
I keep going over this, but it is so simple, I must be missing something obvious.
Nevermind. :) Not sure what happened to be honest, but I’m getting good responses now. Apologies.
Hi Richard, twitter only gives a certain amount of requests per hour by default (150 per hour by the looks of things). If you do create an application that does justifiably require more requests, you can ask Twitter for a limit increase.
this is a great script