<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>untoldentertainment.com &#187; Twitter</title>
	<atom:link href="http://www.untoldentertainment.com/blog/tag/twitter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.untoldentertainment.com/blog</link>
	<description>We Make Flash Games</description>
	<lastBuildDate>Wed, 01 Feb 2012 15:18:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<copyright>Copyright &#xA9; untoldentertainment.com 2011 </copyright>
	<managingEditor>ryan@untoldentertainment.com (untoldentertainment.com)</managingEditor>
	<webMaster>ryan@untoldentertainment.com (untoldentertainment.com)</webMaster>
	<image>
		<url>http://www.untoldentertainment.com/blog/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
		<title>untoldentertainment.com</title>
		<link>http://www.untoldentertainment.com/blog</link>
		<width>144</width>
		<height>144</height>
	</image>
	<itunes:subtitle></itunes:subtitle>
	<itunes:summary>We Make Flash Games</itunes:summary>
	<itunes:keywords></itunes:keywords>
	<itunes:category text="Society &#38; Culture" />
	<itunes:author>untoldentertainment.com</itunes:author>
	<itunes:owner>
		<itunes:name>untoldentertainment.com</itunes:name>
		<itunes:email>ryan@untoldentertainment.com</itunes:email>
	</itunes:owner>
	<itunes:block>no</itunes:block>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.untoldentertainment.com/blog/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg" />
		<item>
		<title>If Miyamoto Went Indie &#8230;</title>
		<link>http://www.untoldentertainment.com/blog/2011/12/08/if-miyamoto-went-indie/</link>
		<comments>http://www.untoldentertainment.com/blog/2011/12/08/if-miyamoto-went-indie/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 21:32:11 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Awesomazing]]></category>
		<category><![CDATA[hashtag games]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Video Games]]></category>

		<guid isPermaLink="false">http://www.untoldentertainment.com/blog/?p=4221</guid>
		<description><![CDATA[Wired reports that legendary video game developer Shigeru Miyamoto is stepping down from his role at Nintendo overseeing the company&#8217;s large video game projects. Miyamoto, who was behind some of the biggest video game franchises including The Legend of Zelda, Super Mario Bros., Star Fox, Pikmin, Donkey Kong and Nintendogs, says he wants to work [...]]]></description>
			<content:encoded><![CDATA[<p><b>Wired</b> reports that legendary video game developer <a href="http://www.wired.com/gamelife/2011/12/miyamoto-interview/">Shigeru Miyamoto is stepping down</a> from his role at Nintendo overseeing the company&#8217;s large video game projects.  Miyamoto, who was behind some of the biggest video game franchises including <b>The Legend of Zelda</b>, <b>Super Mario Bros.</b>, <b>Star Fox</b>, <b>Pikmin</b>, <b>Donkey Kong</b> and <b>Nintendogs</b>, says he wants to work on smaller projects with shorter timespans.  This led many Twitter adherents to comment that Miyamoto was going &#8220;indie&#8221;, joining the ranks of self-funded, hipster game developers.  i took the concept and ran with it in this Twitter hash tag game.</p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2011_12_08/graveyard.jpg" alt="Link in the Graveyard"></p>
</div>
<ul>
<li><b>#ifMiyamotoWentIndie</b> Link would just &#8230; you know &#8230; wander around. No enemies, no struggle &#8230; just piano.
<li><b>#ifMiyamotoWentIndie</b> Every game stars Luigi.
<li><b>#ifMiyamotoWentIndie</b> Mario would walk RIGHT to LEFT. Doesn&#8217;t that BLOW your MIND??
<li><b>#ifMiyamotoWentIndie</b> He&#8217;d crash on someone&#8217;s couch at #GDC, lobby-surf for the first few days, and only spring for an Expo pass.
<li><b>#ifMiyamotoWentIndie</b> The smashable barrels in Donkey Kong would be labeled &#8220;hope&#8221;, &#8220;ambition&#8221;, &#8220;faith&#8221; and &#8220;mother&#8221;.
<li><b>#ifMiyamotoWentIndie</b> After your first crash in ExciteBike, the rest of the game would be about your slow, painful road to rehabilitation.
<li><b>#ifMiyamotoWentIndie</b> A Star Fox game would last five minutes, and involve a sub-plot about a stillborn son.
<li><b>#ifMiyamotoWentIndie</b> Ocarina of Time would pale in comparison to the series&#8217; crown jewel, Zelda II: The Adventure of Link.
<li><b>#ifMiyamotoWentIndie</b> He&#8217;d be making this really awesome MMO but, you know &#8211; it&#8217;s not ready yet.
<li><b>#ifMiyamotoWentIndie</b> He&#8217;d make a twin-stick tower defense platformer for XBLiG using copyrighted spritesheets from an old Genesis import.
<li><b>#ifMiyamotoWentIndie</b> He&#8217;d show upto #IndieCade and give a meandering talk using words he remembered from his first-year Psych class.
<li><b>#ifMiyamotoWentIndie</b> Kid Icarus would say &#8220;fuck&#8221; a lot.
<li><b>#ifMiyamotoWentIndie</b> He&#8217;d accept his #IGF award by French-kissing Cactus and kicking over an amp on his way off the stage.
<li><b>#ifMiyamotoWentIndie</b> The hookshot would be a metaphor for how we all need to cling to something.
<li><b>#ifMiyamotoWentIndie</b> Nintendogs would be essentially the same, except you could REVERSE TIME.
<li><b>#ifMiyamotoWentIndie</b> He&#8217;d release Stage Debut, and it would sweep the #IGF.
<li><b>#ifMiyamotoWentIndie</b> Samus Aran would take off her codpiece and reveal that she&#8217;s a DUDE.
<li><b>#ifMiyamotoWentIndie</b> Mario Extreme Unicycling.
<li><b>#ifMiyamotoWentIndie</b> Mario Power Hackey Sack.
<li><b>#ifMiyamotoWentIndie</b> He&#8217;d spent most of his afternoons in the &#8220;Mushroom Kingdom&#8221;.
<li><b>#ifMiyamotoWentIndie</b> You&#8217;d be able to fly one beta mission in Starfox, and he&#8217;d charge twenty bucks for it. And then make 4 million dollars.
<li><b>#ifMiyamotoWentIndie</b> He&#8217;d give you naming rights to the monkey at the top of the level if you bid more than $1000 on Kickstarter.
<li><b>#ifMiyamotoWentIndie</b> Every Zelda game ever made would show up in a Steam sale for a dollar nintey-five.
<li><b>#ifMiyamotoWentIndie</b> You&#8217;d take Super Mario down into a water level from which you&#8217;d never be able to escape.
<li><b>#ifMiyamotoWentIndie</b> He&#8217;d grow his hair out, take up smoking, and start calling himself &#8220;the Moto.&#8221; But, you know. Whatever.
<li><b>#ifMiyamotoWentIndie</b> Plaid goombas.
</ul>
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2011%2F12%2F08%2Fif-miyamoto-went-indie%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2011%2F12%2F08%2Fif-miyamoto-went-indie%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2011/12/08/if-miyamoto-went-indie/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=4221&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2011/12/08/if-miyamoto-went-indie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial: Twitter Updates in Flash Part 2</title>
		<link>http://www.untoldentertainment.com/blog/2009/05/14/tutorial-twitter-updates-in-flash-part-2/</link>
		<comments>http://www.untoldentertainment.com/blog/2009/05/14/tutorial-twitter-updates-in-flash-part-2/#comments</comments>
		<pubDate>Thu, 14 May 2009 20:40:05 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Awesomazing]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.untoldentertainment.com/blog/?p=1290</guid>
		<description><![CDATA[Our first tutorial, Pull Twitter Updates into Flash, got us a bit of attention. So rather than write an entirely new tutorial, we thought we&#8217;d beat a dead horse a little and re-hash some of the same material. We&#8217;re even using the same Fwitter logo. Classy. This tutorial builds on the last one, and helps [...]]]></description>
			<content:encoded><![CDATA[<p>Our first tutorial, <a href="http://www.untoldentertainment.com/blog/2009/04/02/tutorial-pull-twitter-updates-into-flash/">Pull Twitter Updates into Flash</a>, got us a bit of attention.  So rather than write an entirely new tutorial, we thought we&#8217;d beat a dead horse a little and re-hash some of the same material.  </p>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_04_02/fwitter.jpg" alt="Fwitter">
</p>
<p>We&#8217;re even using the same Fwitter logo.  Classy.
</p></div>
<p>This tutorial builds on the last one, and helps us solve an important problem.  Untold Entertainment member and friend of the site <a href="http://www.untoldentertainment.com/boards/memberlist.php?mode=viewprofile&#038;u=56">MichaelJW</a> pointed out last time around that Twitter only allows you to make 100 calls per hour for a given user name. If you&#8217;re fabulously swamped with oodles of traffic, or you&#8217;re like me, suffering from delusions that you will one day be fabulously swamped with oodles of traffic, then this is a problem.  Fortunately, MichaelJW has the solution: simply write to Twitter and ask to be whitelisted, so that you can make all the calls you want!</p>
<p>In short order, you&#8217;ll receive this letter from Twitter:</p>
<blockquote><p>From: <b>Twitter</b><br />
Subject: <b>Your Request for Twitter API whitelisting has been rejected</b></p>
<p><b>Hi Ryan Creighton,</b><br />
Thanks for requesting to be on Twitter&#8217;s API whitelist. Unfortunately, we&#8217;ve rejected your request.<br />
Here&#8217;s why:<br />
Please investigate other strategies to stay within our rate limits: <a href="http://apiwiki.twitter.com/FAQ#HowdoInbspkeepfromrunningintotheratelimit ">http://apiwiki.twitter.com/FAQ#HowdoInbspkeepfromrunningintotheratelimit </a><br />
Please address the issues above and submit another request if appropriate.<br />
<em>The Twitter API Team</em></p></blockquote>
<p>CrapDAMMIT.  That means we&#8217;re actually going to have to do some <em>work</em> to overcome this problem.  Aww &#8230; i <em>hate</em> things that are hard.</p>
<h2>Cold Hard Cache</h2>
<p>i don&#8217;t know what you&#8217;re up to,but i thought this Twitter module idea was pretty cool, so i stuck it at the top of my website in the global nav. That means that every time the page is refreshed, we hit Twitter for a new copy of the tweets.  Also, God kills a kitten or whatever.  So that&#8217;s not being a very good netizen.  Why hammer Twitter with more requests than necessary when we can spend hours of our own time writing a caching script to solve the problem?  Am i right?</p>
<p>So here&#8217;s what we&#8217;re gonna do, in pseudocode:</p>
<ol>
<li>When we load up the module, let&#8217;s check the user&#8217;s Flash cookie to see if we&#8217;ve saved any Twitter data
<li>If the cookie is empty, we&#8217;ll hit the Twitter servers and grab new data.  Then we&#8217;ll save that data for next time.
<li>We&#8217;ll add a time stamp to the Flash cookie so we know how long it&#8217;s been since we grabbed fresh data from Twitter.
<li>If there IS Twitter data in the cookie, let&#8217;s look at how old it is
<li>If it&#8217;s still fresh, there&#8217;s no need to hit Twitter.  We&#8217;ll just display that data.
<li>If it&#8217;s old data, let&#8217;s hit Twitter and get a new copy.
</ol>
<p>(note throughout the tutorial and the code, i use the vernacular &#8220;Flash cookie&#8221;.  The proper term is &#8220;shared object&#8221;, but it&#8217;s a lot harder to remember what the thing does when you call it that.)</p>
<p>How do we know what constitutes &#8220;old&#8221; data?  It&#8217;s right there in the code.  You can set the number of hours, minutes and seconds it takes for the data to expire.  i think setting the expiry to 1 hour is pretty reasonable, but feel free to be as <em>un</em>reasonable as you like with this value.  It&#8217;s your Twitter funeral.</p>
<p>Here comes the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/**********************************************
	 * 
	 *  This fun Twitter widget is brough to you
	 *  by Untold Entertainment Inc, and 
	 *  peanut butter!  Peanut butter: a gooey,
	 *  yummy snack that might kill you.
	 * 
	 *  http://www.untoldentertainment.com
	 * 
	 **********************************************/</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">// Here are all the goodies you're going to need </span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">TextFieldAutoSize</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">NetStatusEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #0066CC;">SharedObject</span>;
 	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">SharedObjectFlushStatus</span>;	
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> twitterXML:<span style="color: #0066CC;">XML</span>; <span style="color: #808080; font-style: italic;">// This holds the xml data</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> cachedTwitterData:<span style="color: #0066CC;">SharedObject</span>; <span style="color: #808080; font-style: italic;">// This stores the data loaded from the Flash cookie</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> twitterPHPScriptPath:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> myTwitterID:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> wereAllowedToWriteToTheFlashCookie:<span style="color: #0066CC;">Boolean</span>; <span style="color: #808080; font-style: italic;">// You can use this value to decide whether or not to make repeated save attempts</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Put your Twitter username here.  For example, ours is &quot;untoldEnt&quot; :</span>
			myTwitterID = <span style="color: #ff0000;">&quot;myTwitterID&quot;</span>; 
&nbsp;
			<span style="color: #808080; font-style: italic;">// Put the path to your php script here:</span>
			twitterPHPScriptPath = <span style="color: #ff0000;">&quot;http://www.yourdomain.com/thePathToYourPHPScript&quot;</span>;
&nbsp;
			wereAllowedToWriteToTheFlashCookie = <span style="color: #000000; font-weight: bold;">true</span>; <span style="color: #808080; font-style: italic;">// (let's be optimistic until we discover otherwise) </span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// Check to see if the user has already retrieved the Twitter updates and stored them in a Flash cookie:</span>
			loadTwitterDataFromFlashCookie<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadTwitterDataFromFlashCookie<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Call up the Twitter data from the Flash cookie on the user's machine:</span>
			cachedTwitterData = <span style="color: #0066CC;">SharedObject</span>.<span style="color: #0066CC;">getLocal</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;twitter&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> timeStamp:<span style="color: #0066CC;">Date</span> = cachedTwitterData.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">timeStamp</span>;
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>timeStamp <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">// The timeStamp variable is in there, which means we've retrieved Twitter info for this user at some point.</span>
&nbsp;
				<span style="color: #808080; font-style: italic;">// Now let's check the timeStamp. If the last time we grabbed Twitter data was too long ago, let's grab fresh info:</span>
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>hasExpired<span style="color: #66cc66;">&#40;</span>timeStamp<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					<span style="color: #808080; font-style: italic;">// The most recent copy of the Twitter data in the Flash cookie is old!  Let's get some fresh data:</span>
					<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cookie has expired!  let's get some fresh data&quot;</span><span style="color: #66cc66;">&#41;</span>;
					loadTwitterXML<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;		
				<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #808080; font-style: italic;">// It hasn't been very long since we grabbed a fresh copy of the Twitter data. Let's just use what we've got in the Flash cookie:</span>
					<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cookie is fresh. display the data.&quot;</span><span style="color: #66cc66;">&#41;</span>;
					twitterXML = cachedTwitterData.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">twitterXML</span>;
					showTwitterStatus<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">// If there's no timeStamp variable in there, then the cookie's empty.  We need to hit Twitter to grab our data for the first time.</span>
				loadTwitterXML<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;				
			<span style="color: #66cc66;">&#125;</span>			
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> saveTwitterDataToFlashCookie<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// This bit tries to write something to the user's Flash cookie. Depending on the user's Flash cookie</span>
			<span style="color: #808080; font-style: italic;">// settings, we may need to ask the user permission before we write to the cookie.  We'll test</span>
			<span style="color: #808080; font-style: italic;">// the water by trying to write something to the cookie:</span>
            <span style="color: #000000; font-weight: bold;">var</span> flushStatus:<span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">null</span>;
            <span style="color: #0066CC;">try</span>
			<span style="color: #66cc66;">&#123;</span>
                flushStatus = cachedTwitterData.<span style="color: #0066CC;">flush</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10000</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span> <span style="color: #0066CC;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">error</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Error...Could not write SharedObject to disk<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
			<span style="color: #808080; font-style: italic;">// If we were able to write to the Flash cookie, let's see if the user was prompted to allow us or not:</span>
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>flushStatus <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">switch</span> <span style="color: #66cc66;">&#40;</span>flushStatus<span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					<span style="color: #808080; font-style: italic;">// The user is only allowing us to write a very small amount of data to the Flash cookie, and has asked</span>
					<span style="color: #808080; font-style: italic;">// Flash to prompt him so that he can give permission to write something larger.  Let's wait until the</span>
					<span style="color: #808080; font-style: italic;">// user clicks to give that permission:</span>
                    <span style="color: #b1b100;">case</span> SharedObjectFlushStatus.<span style="color: #006600;">PENDING</span>:
                        <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Requesting permission to save object...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
                        cachedTwitterData.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>NetStatusEvent.<span style="color: #006600;">NET_STATUS</span>, onFlushStatus<span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #b1b100;">break</span>;
					<span style="color: #808080; font-style: italic;">// We're home-free: we can write to the cookie, and the amount of data is small enough to fly under the</span>
					<span style="color: #808080; font-style: italic;">// user's Flash cookie permission radar.  Let's write some data!</span>
                    <span style="color: #b1b100;">case</span> SharedObjectFlushStatus.<span style="color: #006600;">FLUSHED</span>:
                        <span style="color: #808080; font-style: italic;">//trace(&quot;Value flushed to disk.\n&quot;);</span>
						<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;********* save complete. ***********<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
						finishedHandlingTwitterData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #b1b100;">break</span>;
                <span style="color: #66cc66;">&#125;</span>
            <span style="color: #66cc66;">&#125;</span>				
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onFlushStatus<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:NetStatusEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;User closed permission dialog...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #b1b100;">switch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">info</span>.<span style="color: #006600;">code</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;SharedObject.Flush.Success&quot;</span>:
                    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;User granted permission -- value saved.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
					finishedHandlingTwitterData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                    <span style="color: #b1b100;">break</span>;
				<span style="color: #808080; font-style: italic;">// Dammit!  In this case, the user freaked out and won't let us write anything to his Flash cookie.</span>
				<span style="color: #808080; font-style: italic;">// We'll have to hit Twitter every single time solely for this user's benefit.</span>
                <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;SharedObject.Flush.Failed&quot;</span>:
                    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;User denied permission -- value not saved.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
					wereAllowedToWriteToTheFlashCookie = <span style="color: #000000; font-weight: bold;">false</span>;
                    <span style="color: #b1b100;">break</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            cachedTwitterData.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>NetStatusEvent.<span style="color: #006600;">NET_STATUS</span>, onFlushStatus<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>	
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> finishedHandlingTwitterData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Twitter data saved.&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> hasExpired<span style="color: #66cc66;">&#40;</span>timeStamp:<span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Store the date RIGHT NOW, to compare against the Flash cookie timeStamp:</span>
			<span style="color: #000000; font-weight: bold;">var</span> now:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Let's say that the cookie expires after 1 hour, 0 minutes and zero seconds:</span>
			<span style="color: #000000; font-weight: bold;">var</span> expiryHours:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1</span>;
			<span style="color: #000000; font-weight: bold;">var</span> expiryMinutes:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
			<span style="color: #000000; font-weight: bold;">var</span> expirySeconds:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Store some handy conversion values:</span>
			<span style="color: #000000; font-weight: bold;">var</span> msPerHour:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">3600000</span>;
			<span style="color: #000000; font-weight: bold;">var</span> msPerMinute:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">60000</span>;
			<span style="color: #000000; font-weight: bold;">var</span> msPerSecond:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1000</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Multiply those values to get the expiry time in milliseconds:</span>
			<span style="color: #000000; font-weight: bold;">var</span> expiryTime:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>expiryHours <span style="color: #66cc66;">*</span> msPerHour<span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span>expiryMinutes <span style="color: #66cc66;">*</span> msPerMinute<span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span>expirySeconds <span style="color: #66cc66;">*</span> msPerSecond<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Return whether or not the timeStamp is past the expiry date:</span>
			<span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span>now.<span style="color: #0066CC;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> - timeStamp.<span style="color: #0066CC;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> expiryTime<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadTwitterXML<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> urlLoader:URLLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// When all the junk has been pulled in from the url, we'll fire finishedLoadingXML:</span>
			urlLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, finishLoadingXML<span style="color: #66cc66;">&#41;</span>;
			urlLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>twitterPHPScriptPath + <span style="color: #ff0000;">&quot;?twitterId=&quot;</span> + myTwitterID<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;			
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> finishLoadingXML<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// All the junk has been pulled in from the xml!  Hooray!</span>
			<span style="color: #808080; font-style: italic;">// Remove the eventListener as a bit of housecleaning:</span>
			<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, finishLoadingXML<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Populate the xml object with the xml data:</span>
			twitterXML = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
&nbsp;
			cachedTwitterData = <span style="color: #0066CC;">SharedObject</span>.<span style="color: #0066CC;">getLocal</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;twitter&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Set the date/time RIGHT NOW:</span>
			cachedTwitterData.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">timeStamp</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// Store the twitterXML data:</span>
			cachedTwitterData.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">twitterXML</span> = twitterXML;	
			<span style="color: #808080; font-style: italic;">// (Try to) save the whole shebang the user's Flash cookie: </span>
			saveTwitterDataToFlashCookie<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			showTwitterStatus<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> showTwitterStatus<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;showTwitterStatus&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// Uncomment these lines if you want to see all the fun stuff Twitter sends you:</span>
			<span style="color: #808080; font-style: italic;">//trace(twitterXML);</span>
			<span style="color: #808080; font-style: italic;">//trace(twitterXML.head);</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// Prep the text field to hold our latest Twitter update:</span>
			twitter_txt.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			twitter_txt.<span style="color: #0066CC;">autoSize</span> = TextFieldAutoSize.<span style="color: #0066CC;">LEFT</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Populate the text field with the first element in the status.text nodes:</span>
			twitter_txt.<span style="color: #0066CC;">htmlText</span> = twitterXML.<span style="color: #0066CC;">status</span>.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>This is just a modified version of the code we used last time, with the caching stuff added in.  It&#8217;s very well commented.  If you&#8217;re new to the concept of Flash cookies, take a careful read-through and make yourself smart.</p>
<h2>I Did it All for the Cookie</h2>
<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_05_14/cookiemonster.jpg" alt="Cookie Monster">
</p>
<p>Now DAT a lot of code.
</p></div>
<p>i added one flag to the code called <b>wereAllowedToWriteToTheFlashCookie</b>.  Time was, no one knew about Flash cookies, and you could get away with murder.  Nowadays, some folks are wise to the fact that Flash can store stuff to their computers, and they&#8217;re blocking access, or cranking the permission slider down so that barely any data can be stored to their computers.  If this is the case, and you try to store a Flash cookie, a dialogue box will pop up and ask the user to authorize the cookie-writing procedure.  If the player says &#8220;no&#8221;, we&#8217;re flagging the <b>wereAllowedToWriteToTheFlashCookie</b> to <b>false</b>.</p>
<p>This tutorial doesn&#8217;t really make any further use of that value.  But if you check out our super-deluxe version of this module at the top of the Untold Entertainment site, you&#8217;ll notice we added paging controls so that users can flip through the last twenty Twitter messages, and an auto-refresh countdown that displays the next tweet automatically.  One of the things i noticed was that if you move around the site quickly, the bird keeps tweeting the most recent post.  That&#8217;s kind of boring.</p>
<p>What i&#8217;d like to do (which i may have already done, depending on when you read this), is to save the currentTweet number every time it changes.  That way, when the page refreshes, i can retrieve the currentTweet number from the Flash cookie and pick up where i left off.  BUT if the user isn&#8217;t allowing Flash cookies, he&#8217;s gonna see that &#8220;Allow?&#8221; dialogue pop up every time i try to save the currentTweet number.  And that stinks.  That guy&#8217;s not likely to pay a repeat visit.</p>
<p>So i&#8217;ll check the <b>wereAllowedToWriteToTheFlashCookie</b> flag before i try to save anything else to the Flash cookie.</p>
<p>And by then, the Twitter module on our site will be just about as awesomazing as possible.</p>
<h2>Making it Work</h2>
<p>If this is your first time with these Twitter tutorials, you might make some mistakes.  And then you might blame those mistakes on us.  Rest assured, the code works.  You&#8217;re probably doing something silly.  Make sure you test this on a web server, because the Flash IDE lies to you, and generally won&#8217;t tell you when there&#8217;s a securty sandbox issue.  Please check the comments at the bottom of these posts to make sure you&#8217;re not making the same mistake that someone else has made before you.  We&#8217;re not that great at troubleshooting this stuff, because we&#8217;re usually too busy chasing after the next shiny object to pay proper attention to you.  When in doubt, use the <a href="http://www.untoldentertainment.com/boards/">boards</a> to discuss.  By signing up on our boards, you get the added benefit of being awesome.</p>
<p>You can download the source code for this tutorial here:</p>
<p><a href="http://www.untoldentertainment.com/blog/tutorials/twitter_pt2/cachedTwitterUpdatesInFlash.zip">cachedTwitterUpdatesInFlash.zip</a></p>
<p>For more Flash AS3 Tutorials and a pile of other useful stuff, check out our <a href="http://www.untoldentertainment.com/blog/flash-and-actionscript-911/">Flash and Actionscript 911</a> feature.</p>
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F05%2F14%2Ftutorial-twitter-updates-in-flash-part-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F05%2F14%2Ftutorial-twitter-updates-in-flash-part-2%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2009/05/14/tutorial-twitter-updates-in-flash-part-2/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=1290&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2009/05/14/tutorial-twitter-updates-in-flash-part-2/feed/</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
		<item>
		<title>Tutorial: Pull Twitter Updates into Flash</title>
		<link>http://www.untoldentertainment.com/blog/2009/04/02/tutorial-pull-twitter-updates-into-flash/</link>
		<comments>http://www.untoldentertainment.com/blog/2009/04/02/tutorial-pull-twitter-updates-into-flash/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 16:11:02 +0000</pubDate>
		<dc:creator>Ryan Henson Creighton</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.untoldentertainment.com/blog/?p=1042</guid>
		<description><![CDATA[That&#8217;s right &#8211; i said &#8220;Fwitter&#8221; It&#8217;s a very simple thing to display your Twitter updates in a Flash widget. We&#8217;re going to use the xml feed, because that&#8217;s what i&#8217;m most comfy with. Unfortunately, you can&#8217;t grab the xml feed from Twitter&#8217;s site, because they&#8217;ve locked their crossdomain policy file &#8230; but you can [...]]]></description>
			<content:encoded><![CDATA[<div class="displayed">
<p><img src="http://www.untoldentertainment.com/blog/img/2009_04_02/fwitter.jpg" alt="Fwitter">
</p>
<p>That&#8217;s right &#8211; i said &#8220;Fwitter&#8221;
</p></div>
<p>It&#8217;s a very simple thing to display your Twitter updates in a Flash widget. We&#8217;re going to use the xml feed, because that&#8217;s what i&#8217;m most comfy with.  Unfortunately, you can&#8217;t grab the xml feed from Twitter&#8217;s site, because they&#8217;ve locked their crossdomain policy file &#8230; but you can pull down the data using any other damned process.  Here&#8217;s the basic flow you have to follow:</p>
<ol>
<li>Hit a PHP page or javascript function from Flash (we&#8217;ll use PHP)
<li>Parse the XML data that the call returns
<li>Display the goodies in your Flash app
</ol>
<h2>Here Comes the Code</h2>
<p>This is the Actionscript 3 code you&#8217;ll need:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/**********************************************
	 * 
	 *  This fun Twitter widget is brough to you
	 *  by Untold Entertainment Inc, and 
	 *  peanut butter!  Peanut butter: a gooey,
	 *  yummy snack that might kill you.
	 * 
	 *  http://www.untoldentertainment.com
	 * 
	 **********************************************/</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">// Here are all the goodies you're going to need </span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">TextFieldAutoSize</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> twitterXML:<span style="color: #0066CC;">XML</span>; <span style="color: #808080; font-style: italic;">// This holds the xml data</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Put your Twitter username here.  For example, ours is &quot;untoldEnt&quot; :</span>
			<span style="color: #000000; font-weight: bold;">var</span> myTwitterID:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;myTwitterID&quot;</span>; 
			<span style="color: #808080; font-style: italic;">// Put the path to your php script here:</span>
			<span style="color: #000000; font-weight: bold;">var</span> twitterPHPScriptPath:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;http://www.yourdomain.com/thePathToYourPHPScript&quot;</span>;
			<span style="color: #808080; font-style: italic;">// Fire the loadTwitterXML method, passing it the url to your Twitter info:</span>
			loadTwitterXML<span style="color: #66cc66;">&#40;</span>twitterPHPScriptPath + <span style="color: #ff0000;">&quot;?twitterId=&quot;</span> + myTwitterID<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadTwitterXML<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">URL</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> urlLoader:URLLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// When all the junk has been pulled in from the url, we'll fire finishedLoadingXML:</span>
			urlLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, finishLoadingXML<span style="color: #66cc66;">&#41;</span>;
			urlLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">URL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;			
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> finishLoadingXML<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// All the junk has been pulled in from the xml!  Hooray!</span>
			<span style="color: #808080; font-style: italic;">// Remove the eventListener as a bit of housecleaning:</span>
			<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, finishLoadingXML<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Populate the xml object with the xml data:</span>
			twitterXML = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
			showTwitterStatus<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> showTwitterStatus<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Uncomment this line if you want to see all the fun stuff Twitter sends you:</span>
			<span style="color: #808080; font-style: italic;">//trace(twitterXML);</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// Prep the text field to hold our latest Twitter update:</span>
			twitter_txt.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			twitter_txt.<span style="color: #0066CC;">autoSize</span> = TextFieldAutoSize.<span style="color: #0066CC;">LEFT</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// Populate the text field with the first element in the status.text nodes:</span>
			twitter_txt.<span style="color: #0066CC;">htmlText</span> = twitterXML.<span style="color: #0066CC;">status</span>.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>And here&#8217;s the PHP code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$twitterId</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;twitterId&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;twitterId&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$twitterId</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://twitter.com/statuses/user_timeline/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$twitterId</span>  <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.xml&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Et voila!  Your latest Twitter update appears in a text box on the stage.</p>
<p>
<object width="550" height="100">
<param name="movie" value="http://www.untoldentertainment.com/blog/tutorials/twitter/twitterUpdatesInFlash.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="transparent"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<embed type="application/x-shockwave-flash" width="550" height="100" src="http://www.untoldentertainment.com/blog/tutorials/twitter/twitterUpdatesInFlash.swf" quality="high" bgcolor="#FFFFFF" wmode="transparent" menu="false" ></embed>
</object>
</p>
<p>(<b>note:</b> this tutorial assumes you have a textField on the stage named &#8220;twitter_txt&#8221;)</p>
<p>Twitter exposes a pile of other information, including time stamp, post count, number of followers, etc etc that you can play around with.  This simple example should get you started, anyway.</p>
<p>You can download the source code here:</p>
<p><a href="http://www.untoldentertainment.com/blog/tutorials/twitter/twitterUpdatesInFlash.zip">twitterUpdatesInFlash.zip</a></p>
<p>Big thanks to Jeffie G for writing the PHP code to circumvent Twitter&#8217;s silly security restriction.</p>
<p>Don&#8217;t miss the second part of this tutorial:</p>
<p><a href="http://www.untoldentertainment.com/blog/2009/05/14/tutorial-twitter-updates-in-flash-part-2/">Tutorial: Twitter Updates in Flash Part 2</a></p>
<p>For more Flash AS3 Tutorials and a pile of other useful stuff, check out our <a href="http://www.untoldentertainment.com/blog/flash-and-actionscript-911/">Flash and Actionscript 911</a> feature.
<div class="tweetmeme_button" style="margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F04%2F02%2Ftutorial-pull-twitter-updates-into-flash%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.untoldentertainment.com%2Fblog%2F2009%2F04%2F02%2Ftutorial-pull-twitter-updates-into-flash%2F&amp;source=untoldent&amp;style=normal&amp;service_api=R_44463fc40e5eda8ec585b4088e695066&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p class="fbconnect_share"><fb:share-button class="url" href="http://www.untoldentertainment.com/blog/2009/04/02/tutorial-pull-twitter-updates-into-flash/" /></p><img src="http://www.untoldentertainment.com/blog/?ak_action=api_record_view&id=1042&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.untoldentertainment.com/blog/2009/04/02/tutorial-pull-twitter-updates-into-flash/feed/</wfw:commentRss>
		<slash:comments>135</slash:comments>
		</item>
	</channel>
</rss>

