Twitter and Flash (twitterscript)

For those of you trying to create a twitter vs flash mash-up, hopefully this will help.

  1. Download an svn client, such as TortoiseSVN (http://tortoisesvn.net/downloads)
  2. Using your client, download the latest .as (AS3) files from http://twitterscript.googlecode.com/svn/trunk
  3. Create a new Flash AS3 file
  4. Create a new ‘Document class’, named TwitterUserFeed.as, and assign it to your newly created Flash file
  5. Add the following code to your document class (updating your package name and TWITTER_USER accordingly)
  6. Publish the movie and watch the ‘output’ panel
  7. 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)
			}
		}
	}
}
Share:
  • Facebook
  • MySpace
  • Digg
  • del.icio.us
  • Reddit
  • StumbleUpon
  • TwitThis
  • Slashdot
  • Technorati
This entry was posted in Flash, Twitter and tagged , , , , , . Bookmark the permalink.

11 Responses to Twitter and Flash (twitterscript)

  1. Dan says:

    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.”

  2. TrevorB says:

    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?

  3. Dan says:

    got it working. thanks. had to move it up one folder.

  4. joshk says:

    hi there,
    how do you get around the security sandbox issue once you publish to a server? this example works great btw,
    josh

  5. TrevorB says:

    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 :)

  6. NRC says:

    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?

  7. Pingback: Johannes Luderschmidt’s Blog » Blog Archive » Twitter AS3 library TwitterScript Flex Example

  8. RichardG says:

    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.

  9. RichardG says:

    Nevermind. :) Not sure what happened to be honest, but I’m getting good responses now. Apologies.

  10. TrevorB says:

    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.

  11. Danny says:

    this is a great script

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>