Twitter AS3 library TwitterScript Flex Example

I have been looking around for Actionscript 3 libraries for the retrieval of data via the very nice Twitter API. Basically, TwitterScript seems to be a good choice for a Twitter Flash library as it wraps Twitter query URLs and packs the XML results automatically in arrays.

Twitter Banner

However, as so often with Actionscript libraries there is NO documentation pertaining TwitterScript available on its Google code page, there is no example included in the source code and the source code is not commented. What could be so difficult about providing a little piece of code like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
      addedToStage="init()">
  <mx:Script>
    <![CDATA[
      import twitter.api.data.TwitterStatus;
      import twitter.api.events.TwitterEvent;
      import twitter.api.TwitterSearch;
        import twitter.api.Twitter;
 
      private static const TWITTER_USER:String = "stephenfry";
 
      private var _twitter:Twitter;
      private var _twitterSearch:TwitterSearch;
 
      private function init():void{
        _twitter = new Twitter();
        _twitterSearch = new TwitterSearch();
 
        _twitter.loadUserTimeline(TWITTER_USER);
        _twitter.addEventListener(TwitterEvent.ON_USER_TIMELINE_RESULT, 
            userTimelineResult);
 
        _twitterSearch.addKeyword("ipad");
        _twitter.addEventListener(TwitterEvent.ON_SEARCH, onSearchResult, 
            false,0,true);
        _twitter.search(_twitterSearch);
      }
 
      private function userTimelineResult(e:TwitterEvent):void {
        var twitterStatus:TwitterStatus;
        for (var i in e.data) {
          twitterStatus = e.data[i]
          trace("user tweets",twitterStatus.text)
        }
      }
 
      private function onSearchResult(event : TwitterEvent) : void{
        var twitterStatus : TwitterStatus;
        for (var i : int = 0; i < event.data.length; i++){
          twitterStatus = event.data[i];
          trace("search result:",twitterStatus.text);
        }
      }
    ]]>
  </mx:Script>
</mx:Application>

This example originates to Trevor Boyle’s blog. Improved by Kimi.

Published by Johannes Luderschmidt

About this blog