<?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/"
	>

<channel>
	<title>blackcj.com</title>
	<atom:link href="http://www.blackcj.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blackcj.com/blog</link>
	<description>Cutting edge development with Adobe Flex, ActionScript and AIR</description>
	<lastBuildDate>Mon, 01 Mar 2010 21:35:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Define Popup Window Size in HTML Text</title>
		<link>http://www.blackcj.com/blog/2010/03/01/define-popup-window-size-in-html-text/</link>
		<comments>http://www.blackcj.com/blog/2010/03/01/define-popup-window-size-in-html-text/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 21:31:08 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Myth]]></category>
		<category><![CDATA[TextField]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=709</guid>
		<description><![CDATA[Executing JavaScript in a Flash HTML TextField is both cool and a little scary. You can throw some inline JavaScript in your htmlText to dynamically specify a pop up window size when using target="_blank." This works in both ActionScript 2.0 and ActionScript 3.0.
Pop up Window Example:
// 

Example of Inline Java Script

(click on the link above [...]]]></description>
			<content:encoded><![CDATA[<p>Executing JavaScript in a Flash HTML TextField is both cool and a little scary. You can throw some inline JavaScript in your htmlText to dynamically specify a pop up window size when using target="_blank." This works in both ActionScript 2.0 and ActionScript 3.0.</p>
<p><h3>Pop up Window Example:</h3>
<p><script type="text/javascript">// <![CDATA[
 var flashvars = {}; var params = { bgcolor: "ffffff" }; swfobject.embedSWF("http://www.blackcj.com/blog/wp-content/swfs/InlineJavascript/AS3_popup_size.swf", "InlineJavaScript", "300", "100", "9.0.0", "flash/expressInstall.swf", flashvars, params);
// ]]&gt;</script></p>
<div id="InlineJavaScript">
<h1>Example of Inline Java Script</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>
<p><em>(click on the link above to open a 200 x 300 pop up window)</em>
</p>
<div class="igBar"><span id="lactionscript-2"><a href="#" onclick="javascript:showPlainTxt('actionscript-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-2">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// myTextField is a dynamic text field instance on the stage</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> link:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">"http://www.blackcj.com/"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> jsText:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">"window.open('"</span> + link + <span style="color: #ff0000;">"','win','height=200,width=300,toolbar=no,scrollbars=yes'); void(0);"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">myTextField.<span style="color: #0066CC;">htmlText</span> = <span style="color: #ff0000;">"&lt;a href=<span style="color: #000099; font-weight: bold;">\"</span>javascript:"</span> + jsText + <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\"</span>&gt;&lt;u&gt;blackcj.com&lt;/u&gt;&lt;/a&gt;"</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Any JavaScript tag can be run this way. Try adding an alert right after the window.open script. Notice how they both execute. Yet another reason to ALWAYS validate your input fields when displaying htmlText. Nothing worse than somebody adding some inline JavaScript to your Flash form.</p>
<p>
<strong>Resources</strong><br />
<a href="http://www.webmasterworld.com/html/3429895.htm">http://www.webmasterworld.com/html/3429895.htm</a><br />
<a href="http://kb2.adobe.com/cps/141/tn_14192.html">http://kb2.adobe.com/cps/141/tn_14192.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2010/03/01/define-popup-window-size-in-html-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cut the Drama. Flash is Here to Stay.</title>
		<link>http://www.blackcj.com/blog/2010/02/01/cut-the-drama-flash-is-here-to-stay/</link>
		<comments>http://www.blackcj.com/blog/2010/02/01/cut-the-drama-flash-is-here-to-stay/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 05:00:27 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Myth]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=682</guid>
		<description><![CDATA[I really wish that Steve Jobs would quit misinforming the public. It amazes me that Apple and Adobe's childish feud is even news worthy. I've had a number of people tell me that I should start looking for a new profession because HTML5 is the future and Flash is dead (link). All of them iPhone [...]]]></description>
			<content:encoded><![CDATA[<p>I really wish that Steve Jobs would quit misinforming the public. It amazes me that Apple and Adobe's childish feud is even news worthy. I've had a number of people tell me that I should start looking for a new profession because HTML5 is the future and Flash is dead (<a href="http://www.wired.com/epicenter/2010/01/googles-dont-be-evil-mantra-is-bullshit-adobe-is-lazy-apples-steve-jobs/">link</a>). All of them iPhone users and each of them were just tech savvy enough not to know what the hell they were talking about. Here is ten minutes worth of research to show Steve Jobs' opinion on the matter is a bit more like a leap of blind faith.</p>
<p><a href="http://www.blackcj.com/blog/wp-content/uploads/2010/02/jobgraph.png"><img src="http://www.blackcj.com/blog/wp-content/uploads/2010/02/jobgraph.png" alt="" title="Job Graph" width="540" height="300" class="alignnone size-full wp-image-684" /></a></p>
<p><strong>What does this graph tell us?</strong><br />
Well, even through a recession, ActionScript job growth has held strong. Objective C on the other hand looks very unstable.</p>
<p><a href="http://www.blackcj.com/blog/wp-content/uploads/2010/02/trends.png"><img src="http://www.blackcj.com/blog/wp-content/uploads/2010/02/trends.png" alt="" title="Salary Trends" width="540" height="269" class="alignnone size-full wp-image-685" /></a></p>
<p><strong>And this one?</strong><br />
Nobody seems to be able to make up their mind about how much to pay Objective C programmers. Is it worth more than HTML or not? Would you work in a development language that had the potential for a 50% pay cut if you lost your job?</p>
<p><a href="http://www.blackcj.com/blog/wp-content/uploads/2010/02/Web_development_timeline.png"><img src="http://www.blackcj.com/blog/wp-content/uploads/2010/02/Web_development_timeline-300x248.png" alt="" title="Web Development Timeline" width="300" height="248" class="alignnone size-medium wp-image-686" /></a><br />
<a href="http://www.hiten.net/wilberwind/wordpress/?p=826"><em>http://www.hiten.net/wilberwind/wordpress/?p=826</em></a></p>
<p><strong>How about this chart?</strong><br />
I would like someone to point out the web development language that died. Anyone? Oh wait... none of them have ever died! When somebody comes out with something better, the competition does the same. Not to mention that it took AJAX nearly ten years to catch on. As much as some people hate PHP, it is still around. As much as some people hate Microsoft, .NET is still kicking. As much as Steve Jobs hates Adobe, Flash is here to stay.</p>
<p>Do I hate HTML5 and think it will fail? No. I hope it succeeds. The reason I code ActionScript is because it is widely supported and cutting edge. HTML4 wasn't enough for me. When HTML5 has a 3D engine, physics support, frameworks, blogs of examples, full browser support, and a great IDE, I'll strongly consider it. Until then, please don't tell me I should look for a new profession. </p>
<p>*Update 02/02/2010 @ 7am in response to a comment below*<br />
<a href="http://www.blackcj.com/blog/wp-content/uploads/2010/02/jobgraph_cf1.png"><img src="http://www.blackcj.com/blog/wp-content/uploads/2010/02/jobgraph_cf1.png" alt="" title="ActionScript Job Trends" width="540" height="300" class="alignnone size-full wp-image-703" /></a></p>
<p><strong>Analysis:</strong><br />
Perl seems to be holding strong. I wish the data went back further, was there ever a significant decline? They still have a pretty big market for jobs with a steady incline. Coldfusion jobs have not gone up but have also not really gone down over the past 5 years. That's pretty good job security for 'dead' languages. </p>
<p>Looks like Silverlight has seen nothing but positive growth over the past few years. Was it two years ago Microsoft and .NET developers where predicting the death of Flash due to Silverlight? Looks like there is enough market for both. If the web wants interactive maybe there is room for Flash, HTML5, and Silverlight to all grow over the next 5 years. Based on the data at hand, that would be my prediction.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2010/02/01/cut-the-drama-flash-is-here-to-stay/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Fix Disappearing Fonts Caused by SWC&#8217;s</title>
		<link>http://www.blackcj.com/blog/2010/01/03/resolve-swc-font-conflicts/</link>
		<comments>http://www.blackcj.com/blog/2010/01/03/resolve-swc-font-conflicts/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 01:15:47 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Myth]]></category>
		<category><![CDATA[SWC]]></category>
		<category><![CDATA[TextField]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=659</guid>
		<description><![CDATA[Have you ever had that feeling that something is very wrong in your project? Maybe that some paranormal force is working against you? Well, when embedded text starts disappearing after adding a SWC to a project, that's the feeling I used to get.
Problem:
Let me start by saying SWC's are great. I've been using them more [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever had that feeling that something is very wrong in your project? Maybe that some paranormal force is working against you? Well, when embedded text starts disappearing after adding a SWC to a project, that's the feeling I used to get.</p>
<p><strong>Problem:</strong><br />
Let me start by saying SWC's are great. I've been using them more and more to include third party API's, utilities and assets. There is one problem, embedding a font into an asset in a SWC will override the internally defined fonts in a project. Why is that bad? Well lets say you have a static text field in your SWC using Georgia and a TextField instance in your Flex project using Georgia. No text will show up in your Flex TextField. Check out this example (notice it starts invisible):</p>
<h3>SWC Text Embed Conflict:</h3>
<p><script type="text/javascript">// <![CDATA[
 var flashvars = {}; var params = { bgcolor: "ffffff" }; swfobject.embedSWF("http://www.blackcj.com/blog/wp-content/swfs/ConflictingFonts/ConflictingFonts.swf", "ConflictingFonts", "300", "240", "9.0.0", "flash/expressInstall.swf", flashvars, params);
// ]]&gt;</script></p>
<div id="ConflictingFonts">
<h1>Example of Conflicting Fonts</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>
<p><em>(switch between MyGeorgia and Georgia fonts to see the disappearing text)</em></p>
<p>Full source code can be found <a href="http://www.blackcj.com/blog/wp-content/swfs/ConflictingFonts/srcview/index.html" target="_blank">here</a>.</p>
<p><strong>Solution:</strong><br />
Define your embed tags in ActionScript with a different fontFamily and fontName. So, if your font is Georgia than name it EmbedGeorgia. This will allow your TextField to reference the correct class definition. In my experience the SWC will always win if there is a conflict.</p>
<div class="igBar"><span id="lactionscript-6"><a href="#" onclick="javascript:showPlainTxt('actionscript-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-6">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">"/assets/fonts/georgia.ttf"</span>, advancedAntiAliasing=<span style="color: #ff0000;">"true"</span>, fontFamily=<span style="color: #ff0000;">"MyGeorgia"</span>, </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; fontName=<span style="color: #ff0000;">"MyGeorgia"</span>, fontWeight=<span style="color: #ff0000;">"normal"</span>, mimeType=<span style="color: #ff0000;">"application/x-font"</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> MyGeorgiaFont:<span style="color: #000000; font-weight: bold;">Class</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const MY_GEORGIA:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">"MyGeorgia"</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>rather than...</p>
<div class="igBar"><span id="lactionscript-7"><a href="#" onclick="javascript:showPlainTxt('actionscript-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-7">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// This will conflict with Georgia references in a SWC!!!</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">"/assets/fonts/georgia.ttf"</span>, advancedAntiAliasing=<span style="color: #ff0000;">"true"</span>, fontFamily=<span style="color: #ff0000;">"Georgia"</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; fontName=<span style="color: #ff0000;">"Georgia"</span>, fontWeight=<span style="color: #ff0000;">"normal"</span>, mimeType=<span style="color: #ff0000;">"application/x-font"</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> GeorgiaFont:<span style="color: #000000; font-weight: bold;">Class</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const GEORGIA:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">"Georgia"</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>It's that easy?</strong><br />
Yup.</p>
<p><strong>What if you have two SWC's with Georgia embedded text?</strong><br />
Will they conflict with each other? Based on the example above the answer is <strong>no</strong>. Awesome!</p>
<p><strong>What if my fonts are stored in a SWF file? </strong><br />
Than duplicate the above code but reference your SWF instead of the font in the assets folder.</p>
<h3>Code that results in invisible text:</h3>
<div class="igBar"><span id="lactionscript-8"><a href="#" onclick="javascript:showPlainTxt('actionscript-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-8">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// This will conflict with Georgia references in a SWC!!!</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">"/assets/fonts/georgia.ttf"</span>, advancedAntiAliasing=<span style="color: #ff0000;">"true"</span>, fontFamily=<span style="color: #ff0000;">"Georgia"</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; fontName=<span style="color: #ff0000;">"Georgia"</span>, fontWeight=<span style="color: #ff0000;">"normal"</span>, mimeType=<span style="color: #ff0000;">"application/x-font"</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> GeorgiaFont:<span style="color: #000000; font-weight: bold;">Class</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const GEORGIA:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">"Georgia"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> georgiaFormat:<span style="color: #0066CC;">TextFormat</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> georgiaText:<span style="color: #0066CC;">TextField</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ConflictingFonts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Component from SWC which uses Georgia in a static text field</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> cc:ColorComponent = <span style="color: #000000; font-weight: bold;">new</span> ColorComponent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; cc.<span style="color: #006600;">colorPicker</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ColorPickerEvent.<span style="color: #006600;">CHANGE</span>, selectColor, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; cc.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;color:#800000;">30</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>cc<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create the local TextFormat</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; georgiaFormat = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextFormat</span><span style="color: #66cc66;">&#40;</span>GEORGIA, <span style="color: #cc66cc;color:#800000;">18</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create the local TextField (the text won't show up!)</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; georgiaText = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; georgiaText.<span style="color: #0066CC;">embedFonts</span> = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; georgiaText.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;color:#800000;">300</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; georgiaText.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;color:#800000;">20</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; georgiaText.<span style="color: #006600;">defaultTextFormat</span> = georgiaFormat;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; georgiaText.<span style="color: #0066CC;">setTextFormat</span><span style="color: #66cc66;">&#40;</span>georgiaFormat<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; georgiaText.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">"Hello World"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>georgiaText<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Swap out the Embed tag, update the TextFormat and you will be good to go.</p>
<h3>Rant:</h3>
<p>On the way to this solution I came up with a number of hacks that appeared to work only to break at the worst time. These hacks included storing a second reference of the font in the SWC (assuming you have access to the source), enumerating through the font list at runtime (which only fixes the problem in debug), and breaking apart the text into bitmaps (you don't want to know how long that takes). Rather than stop using SWC's I started to create more and more of them pushing towards an acceptable solution. This is what I ended up on. Hopefully it will save everyone some time and a little sanity <img src='http://www.blackcj.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2010/01/03/resolve-swc-font-conflicts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Forget to Update Your Adobe Products</title>
		<link>http://www.blackcj.com/blog/2009/12/27/dont-forget-to-update-your-adobe-products/</link>
		<comments>http://www.blackcj.com/blog/2009/12/27/dont-forget-to-update-your-adobe-products/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 20:02:07 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe Updater]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[CS4]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=640</guid>
		<description><![CDATA[Is Flash CS4 crashing when you try to open an FLA? Are you pulling out your hair wondering why Flex 3 doesn't auto complete BitmapData? Adobe Updater may be the answer.
Flash CS4 10.0.2
One of my co-workers called me over to troubleshoot when a folder full of FLAs were crashing Flash CS4 every time he tried [...]]]></description>
			<content:encoded><![CDATA[<p>Is Flash CS4 crashing when you try to open an FLA? Are you pulling out your hair wondering why Flex 3 doesn't auto complete BitmapData? Adobe Updater may be the answer.</p>
<h3>Flash CS4 10.0.2</h3>
<p>One of my co-workers called me over to troubleshoot when a folder full of FLAs were crashing Flash CS4 every time he tried to open them. He had already tried a fresh install of the software and had all of the necessary fonts. So why did it crash? Well it turns out that Flash CS4 had a bug where it would crash when embedded fonts are used.</p>
<p>"FLA crash on open when fonts loaded." -<a href="http://blogs.adobe.com/rgalvan/2009/05/flash_cs4_update_now_available.html" target="_blank">Glavan on Flash</a> <em>(detailed list of what was fixed)</em></p>
<p>After running Adobe Updater everything worked great!</p>
<h3>Flex Builder 3.0.2</h3>
<p>How about Flex Builder? I recently installed Windows 7 with a fresh copy of Flex Builder 3 Professional. Unfortunately I pulled the install from one of my external hard drives and it was version 3.0.1 rather than 3.0.2. A major bug with version 3.0.1 using SDK 3.3 and higher is that BitmapData does not auto complete. After trying multiple versions of the SDK I finally found the <a href="https://bugs.adobe.com/jira/browse/FB-14007" target="_blank">bug report</a> on Adobe Bugs citing that the problem was fixed in version 3.0.2.</p>
<p>After running Adobe Updater everything worked great!</p>
<p>See the common theme here? I tend to disable most of the automatic software updates since they are usually very annoying. After my experiences over the past week I will be checking Adobe Updater much more frequently! <strong>Always update after a fresh install.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2009/12/27/dont-forget-to-update-your-adobe-products/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Base64 Encoding BitmapData</title>
		<link>http://www.blackcj.com/blog/2009/12/22/base64-encoding-bitmapdata/</link>
		<comments>http://www.blackcj.com/blog/2009/12/22/base64-encoding-bitmapdata/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 15:24:24 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Base64]]></category>
		<category><![CDATA[BitmapData]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=608</guid>
		<description><![CDATA[Turn your BitmapData into a string and back! Great for storing images in XML, Databases, or transmitting them over a network. This post will cover Bitmap Encoding, PNG Encoding and JPG Encoding along with the pros and cons for each.

Bitmap Encoding - (link)
PLAIN TEXT
Actionscript:




// Encode


var encoded:String = BitmapEncoder.encodeBase64&#40;bitmap.bitmapData&#41;;


&#160; &#160; 


// Decode


var bd:BitmapData = BitmapEncoder.decodeBase64&#40;encoded&#41;; 






Advantages:
Keep [...]]]></description>
			<content:encoded><![CDATA[<p>Turn your BitmapData into a string and back! Great for storing images in XML, Databases, or transmitting them over a network. This post will cover Bitmap Encoding, PNG Encoding and JPG Encoding along with the pros and cons for each.<br />
<br/></p>
<h3>Bitmap Encoding - (<a href="http://www.foxarc.com/blog/article/56.htm" target="_blank">link</a>)</h3>
<div class="igBar"><span id="lactionscript-12"><a href="#" onclick="javascript:showPlainTxt('actionscript-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-12">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Encode</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> encoded:<span style="color: #0066CC;">String</span> = BitmapEncoder.<span style="color: #006600;">encodeBase64</span><span style="color: #66cc66;">&#40;</span>bitmap.<span style="color: #006600;">bitmapData</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Decode</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> bd:BitmapData = BitmapEncoder.<span style="color: #006600;">decodeBase64</span><span style="color: #66cc66;">&#40;</span>encoded<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
<strong>Advantages:</strong><br />
Keep transparency<br />
Fastest Method<br />
Does not require a Loader</p>
<p><strong>Disadvantages:</strong><br />
Largest Filesize<br />
Will only work with images up to a certain size<br />
<br/></p>
<h3>PNG Encoding - (<a href="http://code.google.com/p/as3corelib/" target="_blank">link</a>)</h3>
<div class="igBar"><span id="lactionscript-13"><a href="#" onclick="javascript:showPlainTxt('actionscript-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-13">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Encode&nbsp; &nbsp;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> ba:ByteArray = PNGEncoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>bitmap.<span style="color: #006600;">bitmapData</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> encoded:<span style="color: #0066CC;">String</span> = Base64.<span style="color: #006600;">encodeByteArray</span><span style="color: #66cc66;">&#40;</span>ba<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Decode&nbsp; &nbsp;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> decoded:ByteArray = Base64.<span style="color: #006600;">decodeToByteArray</span><span style="color: #66cc66;">&#40;</span>encoded<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">loader.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span>decoded<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Advantages:</strong><br />
Keep transparency<br />
Smaller filesize than Bitmap Encoding</p>
<p><strong>Disadvantages:</strong><br />
Slower than Bitmap Encoding<br />
Larger than JPG Encoding<br />
Requires Loader<br />
<br/></p>
<h3>JPG Encoding - (<a href="http://code.google.com/p/as3corelib/" target="_blank">link</a>)</h3>
<div class="igBar"><span id="lactionscript-14"><a href="#" onclick="javascript:showPlainTxt('actionscript-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-14">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Encode</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> jpgEncoder:JPGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPGEncoder<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> ba:ByteArray = jpgEncoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>bitmap.<span style="color: #006600;">bitmapData</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> encoded:<span style="color: #0066CC;">String</span> = Base64.<span style="color: #006600;">encodeByteArray</span><span style="color: #66cc66;">&#40;</span>ba<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Decode</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> decoded:ByteArray = Base64.<span style="color: #006600;">decodeToByteArray</span><span style="color: #66cc66;">&#40;</span>encoded<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">loader.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span>decoded<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
<strong>Advantages:</strong><br />
Smallest Filesize<br />
Variable Quality</p>
<p><strong>Disadvantages:</strong><br />
Slower than Bitmap Encoding<br />
No Transparency<br />
Requires Loader</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2009/12/22/base64-encoding-bitmapdata/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adding Server Side Captcha to Flash Forms</title>
		<link>http://www.blackcj.com/blog/2009/11/23/adding-server-side-captcha-to-flash-forms/</link>
		<comments>http://www.blackcj.com/blog/2009/11/23/adding-server-side-captcha-to-flash-forms/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 17:06:40 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Captcha]]></category>
		<category><![CDATA[Password]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[TextField]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=587</guid>
		<description><![CDATA[Problem:
Flash forms are very vulnerable to attacks.  Spiders may not be able to easily iterate through your Flash content but they can sure spam your form submission URL.  How can you be sure your form was submitted through Flash?  
Definition:
A CAPTCHA or Captcha is a type of challenge-response test used in computing [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong><br />
Flash forms are very vulnerable to attacks.  Spiders may not be able to easily iterate through your Flash content but they can sure spam your form submission URL.  How can you be sure your form was submitted through Flash?  </p>
<p><strong>Definition:</strong><br />
A <a href="http://en.wikipedia.org/wiki/CAPTCHA">CAPTCHA</a> or Captcha is a type of challenge-response test used in computing to ensure that the response is not generated by a computer.</p>
<p><strong>Solution:</strong><br />
What if we have a user drag a circle onto a box?  A spider would have a pretty hard time with that, right?  WRONG.  While this may be a good filter at the view level it still does not solve our problem.  All the hacker would need to do is submit the form correctly one time and use a program like Firebug to sniff the submission URL.  They could then completely bypass your view and submit the form as many times as they want.</p>
<p>The only way to ensure the Flash form is being used is to pull the logic out of the <strong>view</strong> and onto the <strong>server</strong>.  The Flash merely serves up content and never knows what the 'answer' is.  In this example we will use PHP to generate the image, MySQL to store the key value pairs, and Flash to display the content.  This implementation does not require any images to be stored on the server so it NEVER re-uses an existing image.  The PHP generates the image on the fly and serves it directly to the Flash application.</p>
<p>Here is a diagram representing the high level information.  Blue lines represent Captcha generation and the red lines represent the Captcha verification.<br />
<div id="attachment_589" class="wp-caption alignnone" style="width: 370px"><img src="http://www.blackcj.com/blog/wp-content/uploads/2009/11/captcha.jpg" alt="Server Side Captcha in Flash" title="Captcha Diagram" width="360" height="440" class="size-full wp-image-589" /><p class="wp-caption-text">Server Side Captcha in Flash</p></div></p>
<p>Let's start with the PHP.  There are already plenty of PHP scripts out there to generate Captcha.  In this example I re-purposed a script called <a href="http://www.phpcaptcha.org/">Securimage</a>.</p>
<p>First we need a script that will retrieve the image:</p>
<div class="igBar"><span id="lphp-19"><a href="#" onclick="javascript:showPlainTxt('php-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-19">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$flash_id</span> = <span style="color:#0000FF;">$_GET</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'flash_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">include</span> <span style="color:#FF0000;">'securimage.php'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$img</span> = <span style="color:#000000; font-weight:bold;">new</span> securimage<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$img</span>-&gt;<span style="color:#006600;">show</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$flash_id</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">// alternate use:&nbsp; $img-&gt;show('/path/to/background.jpg');</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Next we will need one that verifies the user input with the image:</p>
<div class="igBar"><span id="lphp-20"><a href="#" onclick="javascript:showPlainTxt('php-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$flash_id</span> = <span style="color:#0000FF;">$_GET</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'flash_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span>; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$captcha_text</span> = <span style="color:#0000FF;">$_GET</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'captcha_text'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$flash_id</span> &amp;&amp; <span style="color:#0000FF;">$captcha_text</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$con</span> = <a href="http://www.php.net/mysql_connect"><span style="color:#000066;">mysql_connect</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'localhost'</span>, <span style="color:#FF0000;">'DB_USERNAME'</span>, <span style="color:#FF0000;">'DB_PASSWORD'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$con</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/die"><span style="color:#000066;">die</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Could not connect: '</span> . <a href="http://www.php.net/mysql_error"><span style="color:#000066;">mysql_error</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/mysql_select_db"><span style="color:#000066;">mysql_select_db</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"utils"</span>, <span style="color:#0000FF;">$con</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$result</span> = <a href="http://www.php.net/mysql_query"><span style="color:#000066;">mysql_query</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"SELECT * FROM captcha WHERE flash_id = '"</span>.<span style="color:#0000FF;">$flash_id</span>.<span style="color:#FF0000;">"'"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$match</span> = <span style="color:#CC66CC;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$valid</span> = <span style="color:#CC66CC;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$answer</span> = <span style="color:#FF0000;">"false"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$row</span> = <a href="http://www.php.net/mysql_fetch_array"><span style="color:#000066;">mysql_fetch_array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$result</span>, MYSQL_ASSOC<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$row</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'valid'</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$valid</span> = <span style="color:#CC66CC;color:#800000;">1</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$row</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'captcha_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#0000FF;">$captcha_text</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$match</span> = <span style="color:#CC66CC;color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$answer</span> = <span style="color:#FF0000;">"true"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$valid</span> == <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/mysql_query"><span style="color:#000066;">mysql_query</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"UPDATE captcha SET valid = '0' WHERE flash_id = '"</span>.<span style="color:#0000FF;">$flash_id</span>.<span style="color:#FF0000;">"'"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$answer</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/mysql_close"><span style="color:#000066;">mysql_close</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$con</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now that we have the PHP in place we can create the Flash.  The display logic is separated from the view so you can re-use this code with any server side script.  The Captcha class requires an ID and a URL to the image to display.  It has optional styling parameters to match the look and feel of your webpage.</p>
<p>Generating a Captcha in Flash:</p>
<div class="igBar"><span id="lactionscript-21"><a href="#" onclick="javascript:showPlainTxt('actionscript-21'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-21">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Create a Captcha object</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">_captcha = <span style="color: #000000; font-weight: bold;">new</span> Captcha<span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Create a unique ID so the server can identify the Flash</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">date</span>:<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>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> id:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">""</span> + <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>*<span style="color: #cc66cc;color:#800000;">1000</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">date</span>.<span style="color: #0066CC;">time</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Pass in the url along with the ID so the Captcha can load</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">_captcha.<span style="color: #006600;">loadCaptcha</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"http://www.blackcj.com/utils/securimage_show.php?flash_id="</span> + id, id<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Verifying a Captcha in Flash:</p>
<div class="igBar"><span id="lactionscript-22"><a href="#" onclick="javascript:showPlainTxt('actionscript-22'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-22">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> loader:URLLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, formSuccess, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;color:#800000;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> request:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"http://www.blackcj.com/utils/check_captcha.php?flash_id="</span> + _captcha.<span style="color: #006600;">id</span> + <span style="color: #ff0000;">"&amp;captcha_text="</span> + _text.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>request<span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<h3>Flash Demo and Source:</h3>
<p><script type="text/javascript">// <![CDATA[
 var flashvars = {}; var params = { bgcolor: "ffffff" }; swfobject.embedSWF("http://www.blackcj.com/blog/wp-content/swfs/ServerSideCaptcha/ServerSideCaptcha.swf", "ServerSideCaptcha", "300", "150", "9.0.0", "flash/expressInstall.swf", flashvars, params);
// ]]&gt;</script></p>
<div id="ServerSideCaptcha">
<h1>Server Side Captcha for Flash</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>
<p><em>(click the image to manually refresh the captcha)</em></p>
<p>Full source code for Flash &#038; PHP can be found <a href="http://www.blackcj.com/blog/wp-content/swfs/ServerSideCaptcha/srcview/index.html">here</a>.</p>
<p>In the source code you will need to replace DB_USERNAME and DB_PASSWORD with your username and password.  This example also requires a MySQL database with a table called captcha containing rows <strong>flash_id</strong>, <strong>captcha_id</strong> and <strong>valid</strong>.  Valid is used to ensure the Captcha is only submit one time.  Since we are always generating a new image there is no reason the Captcha should be allowed to be submitted twice with the same id.</p>
<p><strong>Next Steps:</strong><br />
Additional steps could be taken to prevent robots.  Failure rates and number of attempts could be stored for each IP address.  No human should ever attempt to re-submit an old Captcha since each time it is randomly generated.  The system could block anyone that attempted to re-submit a Captcha.</p>
<p>I would eventually like to make this accessible by integrating audio support.  This is a feature of Securimage and would make the utility more versatile.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2009/11/23/adding-server-side-captcha-to-flash-forms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Build a Flash Game in Under 3KB</title>
		<link>http://www.blackcj.com/blog/2009/10/11/build-a-flash-game-in-under-kb/</link>
		<comments>http://www.blackcj.com/blog/2009/10/11/build-a-flash-game-in-under-kb/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 20:58:45 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=554</guid>
		<description><![CDATA[Here are three Flash games each built in under 3KB and in less than 4 hours. They may not be Half Life 2 but they are entertaining! Try your luck at the racing game, platform game, and a space shooter that I like to call Little Ship vs. Space.
Wait? Doesn't everybody have loads of bandwidth? [...]]]></description>
			<content:encoded><![CDATA[<p>Here are three Flash games each built in under 3KB and in less than 4 hours. They may not be Half Life 2 but they are entertaining! Try your luck at the racing game, platform game, and a space shooter that I like to call Little Ship vs. Space.</p>
<p>Wait? Doesn't everybody have loads of bandwidth? Why create a game so small? Well, because it's fun, a good preparation for the 4KB challenge and most importantly size != entertainment. You may spend weeks designing, architecting, and developing a game only to find out it's not fun. <a href="http://blog.iainlobb.com/2009/09/3-minute-lesson-in-game-design-my-talk.html" target="_blank">Evolve your game</a>.</p>
<p>Build a 4KB game. If you enjoy playing it then slowly build it up into something better. Add levels, create graphics, improve the structure but AFTER you've come up with a cool idea. </p>
<p>Lets play some games! Don't forget to vote for your favorite game in the poll bellow the games.</p>
<h3>For all games click on the icon in the top right to re-start.</h3>
<p><strong>Racer Game (1.98KB):</strong><br />
<script type="text/javascript">// <![CDATA[
 var flashvars = {}; var params = { bgcolor: "ffffff" }; swfobject.embedSWF("http://www.blackcj.com/blog/wp-content/swfs/Games/Car.swf", "Car", "500", "400", "9.0.0", "flash/expressInstall.swf", flashvars, params);
// ]]&gt;</script></p>
<div id="Car">
<h1>Racing Game</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>
<p><em>(Use the Left, Right, and Up arrows to move. Try and beat 20 seconds!)</em></p>
<p>Full source for the Racer game: <a href="http://www.blackcj.com/blog/wp-content/swfs/Games/Car.zip">zip</a> (2.09KB)</p>
<p><strong>Coin Collector (2.08KB):</strong><br />
<script type="text/javascript">// <![CDATA[
 var flashvars = {}; var params = { bgcolor: "ffffff" }; swfobject.embedSWF("http://www.blackcj.com/blog/wp-content/swfs/Games/Dude.swf", "Dude", "500", "400", "9.0.0", "flash/expressInstall.swf", flashvars, params);
// ]]&gt;</script></p>
<div id="Dude">
<h1>Coin Collector</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>
<p><em>(Use the Left, Right, and Up arrows to move. Try and beat 16 seconds!)</em></p>
<p><strong>Space Shooter (2.99KB):</strong><br />
<span style="color: #ff0000;"><strong>Notice: MAC users have reported issues with the arrow keys in the Space Shooter game. I will look into this shortly and post a new, functional, version. Looks like I need a MAC to test on <img src='http://www.blackcj.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </strong></span><br />
<script type="text/javascript">// <![CDATA[
 var flashvars = {}; var params = { bgcolor: "000000" }; swfobject.embedSWF("http://www.blackcj.com/blog/wp-content/swfs/Games/LSS.swf", "LSS", "500", "400", "9.0.0", "flash/expressInstall.swf", flashvars, params);
// ]]&gt;</script></p>
<div id="LSS">
<h1>Space Shooter</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>
<p><em>(Use the Left, Right, and Up arrows to move. Ctrl (Command) to fire. Try to get more than 4 frags!)</em></p>
<p></p>
<p><strong>How to do it:</strong><br />
After rudimentary tests Flash CS3 is the best enviornment to compile with. A pure AS3 project in Flex and a project built from CS4 add 500 bytes of overhead (Anyone know why? Maybe meta data?). You also save space by using an external AS file, so create a main.as file for your code. Put all of your code in this one file! Every additional AS file adds space rather than saves. Once your game is setup if you absolutely need one or two extra AS files than make them. Type all of your functions and variables. You'd think it would be the opposite but typed vars take up less space in the compiled SWF. Don't use MouseEvent.CLICK, use "click" to save some bytes.</p>
<p>Now for the game play.  </p>
<p>All three games use the arrow keys as input. Individual key listeners / flags use way to much code!  What are the values for left, right and up arrows? 37, 39, and 38.  None of which are divisible by anything but themselves.  So... lets add one key listener and multiply our single key value by the code value. Up = 38, Up * Left = 1406. That means that key value % expected value == 0 than our key is down. This only works for key values that don't have common denominators, key codes 2 and 4 would not work.  Both 2 and 4 mod 4 would result in true.  Looking back you could also push these codes into an array and do an index check which would allow more flexibility... mod is more fun though.</p>
<div class="igBar"><span id="lactionscript-25"><a href="#" onclick="javascript:showPlainTxt('actionscript-25'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-25">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyboardEvent</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &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></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> k:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;color:#800000;">1</span>; &nbsp;&nbsp;&nbsp;<span style="color: #808080; font-style: italic;">// Keyboard number</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &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></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"enterFrame"</span>, eF<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"keyDown"</span>, kD<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"keyUp"</span>, kU<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> eF<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>k%<span style="color: #cc66cc;color:#800000;">37</span> == <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'rotate object left'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>k%<span style="color: #cc66cc;color:#800000;">39</span> == <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'rotate object right'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>k%<span style="color: #cc66cc;color:#800000;">38</span> == <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'add velocity'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// remove veloicty</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> kD<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>k%<span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span> != <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; k *= <span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> kU<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>k%<span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; k /= <span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Both the Coin Collector and the Racer game use bitmap hit detection which is very little code and very powerful. Bitmap hit detection looks a bit like this:</p>
<div class="igBar"><span id="lactionscript-26"><a href="#" onclick="javascript:showPlainTxt('actionscript-26'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-26">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* Constructor */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Car BitmapData, built in the enter frame function</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sb = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">500</span>, <span style="color: #cc66cc;color:#800000;">400</span>, <span style="color: #000000; font-weight: bold;">true</span>, 0x00000000<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Track BitmapData, doesn't move / change so lets build it here</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tb = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">500</span>, <span style="color: #cc66cc;color:#800000;">400</span>, <span style="color: #000000; font-weight: bold;">true</span>, 0x00000000<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">m = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">m.<span style="color: #006600;">tx</span> = t.<span style="color: #006600;">x</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">m.<span style="color: #006600;">ty</span> = t.<span style="color: #006600;">y</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">tb.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>t, m<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* Enterframe loop */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// First see if bitmap hit detection is needed.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>s.<span style="color: #006600;">hitTestObject</span><span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Clear our car bitmap data object</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; sb.<span style="color: #006600;">fillRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>,<span style="color: #cc66cc;color:#800000;">0</span>,<span style="color: #cc66cc;color:#800000;">500</span>, <span style="color: #cc66cc;color:#800000;">400</span><span style="color: #66cc66;">&#41;</span>, 0x00000000<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Create a matrix that defines the location and rotation of the car</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; m = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; m.<span style="color: #006600;">rotate</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span>/<span style="color: #cc66cc;color:#800000;">180</span><span style="color: #66cc66;">&#41;</span> *s.<span style="color: #006600;">rotation</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; m.<span style="color: #006600;">tx</span> = s.<span style="color: #006600;">x</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; m.<span style="color: #006600;">ty</span> = s.<span style="color: #006600;">y</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Draw the car to our BitmapData using the matrix</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; sb.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>s, m<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Do a hit detection with the track BitmapData</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>tb.<span style="color: #0066CC;">hitTest</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>,<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>, 0xFF, sb, <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>,<span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>, 0x11<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; v = <span style="color: #cc66cc;color:#800000;">1</span>.<span style="color: #cc66cc;color:#800000;">1</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The space game deals with circles so that code uses Trigonometry for hit detection. We'll save that for another day. I need to clean it up a bit for it to really make much sense. Stay tuned for more on games!</p>
<p>Full source for the Racer game: <a href="http://www.blackcj.com/blog/wp-content/swfs/Games/Car.zip">zip</a></p>
<h3>Q/A:</h3>
<p><strong>Why 3KB?</strong><br />
My initial goal was 4KB. I hoarded the KBs so much that they all ended up under 3KB. I suppose that means I should add more features / levels.</p>
<p><strong>Whats with the sudden interest in games?</strong><br />
I actually used to be big into making games back in the AS2 days about 4 years ago. I built out a six level space shooter, 8-ball, and 9-ball billiards. My game programming was shelved for four years until one of my co-workers sparked my interest by mentioning the 4KB challenge <img src='http://www.blackcj.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Can I have the source code for the other two games?</strong><br />
E-mail me with specific questions and I'll be happy to help. I built out the Coin Collector and space games using the Racer as a starting point. It wouldn't be fun if I gave away all the answers <img src='http://www.blackcj.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>People who inspired me to make these games:</strong><br />
<a href="http://blog.iainlobb.com/" target="_blank">Iain Lobb</a><br />
<a href="http://www.gamepoetry.com/blog/2009/02/06/flash-4k-game-competition-prizes-and-rules/" target="_blank">Game Poetry</a><br />
<a href="http://michaelhillsinteractive.com/" target="_blank">Micheal Hills</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2009/10/11/build-a-flash-game-in-under-kb/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Best of Flash on the Beach &#8216;09</title>
		<link>http://www.blackcj.com/blog/2009/10/01/best-of-flash-on-the-beach-09/</link>
		<comments>http://www.blackcj.com/blog/2009/10/01/best-of-flash-on-the-beach-09/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 18:50:08 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=535</guid>
		<description><![CDATA[Back in the U.S. and recovered from jet lag, I've compiled a list of the best sessions, restaurants, beer and more from FOTB09. Plenty of reasons to go back again next year! 
Best Session:
Carlos Ulloa - Hello Enjoy. Carlos, the creator of PV3D, demoed three amazing projects. He even gave some insight as to how [...]]]></description>
			<content:encoded><![CDATA[<p>Back in the U.S. and recovered from jet lag, I've compiled a list of the best sessions, restaurants, beer and more from FOTB09. Plenty of reasons to go back again next year! </p>
<p><strong>Best Session:</strong><br />
Carlos Ulloa - <a href="http://www.helloenjoy.com/" target="_blank">Hello Enjoy</a>. Carlos, the creator of PV3D, demoed three amazing projects. He even gave some insight as to how he solved challenges in those projects and provided a time line of effort between software packages.</p>
<p><strong>Best Code Jam:</strong><br />
Joa Ebert - Live coding. All of the Jam sessions were great but Joa's live coding was beyond words.<br />
<object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=6749871&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=6749871&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
<p><a href="http://vimeo.com/6749871">Joa Ebert's java live coding at Flash on the Beach 2009</a> from <a href="http://vimeo.com/user1303866">Thomas Gabrielsen</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p><a href="http://blog.joa-ebert.com/" target="_blank">http://blog.joa-ebert.com/</a></p>
<p><strong>Best Food:</strong><br />
Bill's - Produce store by day, restaurant by night. I didn't have any bad food in Brighton but this restaurant was the highlight of the trip. A must visit for anyone traveling to Brighton.<br />
<div id="attachment_539" class="wp-caption alignnone" style="width: 498px"><img src="http://www.blackcj.com/blog/wp-content/uploads/2009/10/bills.jpg" alt="Map of Bill&#039;s Restaurant" title="Bill&#039;s Restaurant" width="488" height="340" class="size-full wp-image-539" /><p class="wp-caption-text">Map of Bill's Restaurant</p></div><br />
<a href="http://www.billsproducestore.co.uk/" target="_blank">http://www.billsproducestore.co.uk/</a></p>
<p>Other notable restaurants include Pizza Express, Iguana, Bagleman's and a Japanese restaurant.</p>
<p><strong>Best Beer:</strong><br />
Harveys Best Bitter<br />
<div id="attachment_540" class="wp-caption alignnone" style="width: 260px"><img src="http://www.blackcj.com/blog/wp-content/uploads/2009/10/20081023164742_best.jpg" alt="Harvey&#039;s Best Bitter" title="Harvey&#039;s Best Bitter" width="250" height="187" class="size-full wp-image-540" /><p class="wp-caption-text">Harvey's Best Bitter</p></div></p>
<p><a href="http://www.harveys.org.uk/">http://www.harveys.org.uk/</a></p>
<p><strong>Best Destination:</strong><br />
The Brighton Pier - Loads of rides, food and sights to see at the Brighton Pier. I skipped out on a couple sessions one of the afternoons to check it out. Definitely worth while to check out. Make sure to bring some coins for the arcade machines.</p>
<div id="attachment_548" class="wp-caption alignnone" style="width: 410px"><img src="http://www.blackcj.com/blog/wp-content/uploads/2009/10/Brighton-Pier.jpg" alt="Brighton Pier" title="Brighton Pier" width="400" height="267" class="size-full wp-image-548" /><p class="wp-caption-text">Brighton Pier</p></div>
<p><strong>Best Inspiration Session:</strong><br />
Joel Gethin Lewis - Joel walked through his experiences with Massive Attack and contributions to open source frameworks.</p>
<p><strong>Best Hotel:</strong><br />
Premier Inn - The staff was great, the rooms were clean and the price was reasonable. I would highly recommend the Premier Inn to anyone attending Flash on the Beach or traveling to Brighton.</p>
<p>Until next year!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2009/10/01/best-of-flash-on-the-beach-09/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flash Your TV: the suspense is killing me</title>
		<link>http://www.blackcj.com/blog/2009/09/08/flash-your-tv-the-suspense-is-killing-me/</link>
		<comments>http://www.blackcj.com/blog/2009/09/08/flash-your-tv-the-suspense-is-killing-me/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 16:33:54 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Your TV]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=519</guid>
		<description><![CDATA[A look at some press releases from January 2009. Wait... wasn't that 8 months ago? Both Intel and Broadcom both talk about releasing Flash Lite supported hardware first half of 2009. What happened?
 
Intel and Adobe to Extend Flash Platform to TVs
Jan 5, 2009
"Intel plans to ship the first CE3100 with support for an optimized implementation [...]]]></description>
			<content:encoded><![CDATA[<p>A look at some press releases from January 2009. Wait... wasn't that 8 months ago? Both Intel and Broadcom both talk about releasing Flash Lite supported hardware first half of 2009. What happened?</p>
<p> </p>
<h3><a href="http://www.adobe.com/aboutadobe/pressroom/pressreleases/200901/010509IntelAdobePR.html" target="_blank">Intel and Adobe to Extend Flash Platform to TVs</a></h3>
<p><em>Jan 5, 2009</em></p>
<p>"Intel plans to ship the first CE3100 with support for an optimized implementation of Adobe Flash Lite before mid-2009."</p>
<p>"Adobe and Intel are also working together to bring an optimized implementation of Adobe® AIR™ technology to Intel's digital home platform in the future."</p>
<p> </p>
<h3><a href="http://www.broadcom.com/press/release.php?id=s357665" target="_blank">Collaboration Extends Flash Platform Ecosystem to Digital TVs and Set-Top Boxes</a></h3>
<p><em>Jan 06, 2009</em></p>
<p>"Broadcom DTV and STB platforms with integrated Adobe Flash support are expected to be available to manufacturers in the first half of 2009"</p>
<p>"With Adobe Flash Lite™ 3 software supported... TV viewers will be able to view Flash based content and applications from popular online providers and entertainment sites."</p>
<p> </p>
<h3>Analysis</h3>
<p>According to both of the press releases the hardware will launch with Flash Lite support. Event the latest version of Flash Lite (3.1) is still ActionScript 2.0 (<a href="http://www.adobe.com/products/flashlite/version/" target="_blank">Flash Lite Fact Sheet</a>). The jump from AS2 to AS3 is very significant. The support is built into the hardware which would suggest it will not be upgradable through a software update. Here are three plausible scenarios based on the information at hand:</p>
<p><strong>Scenario 1:</strong><br />
Hardware launches in the upcoming months with AS2 support. The hardware could all be rendered obsolete when AIR support comes out. </p>
<p><strong>Scenario 2:</strong><br />
The eight months of silence could be due to a realization that obsolete hardware is not an ideal solution. Why not wait until AIR support is ready? This is the one I'm hoping for.</p>
<p><strong>Scenario 3:</strong><br />
They may be taking the time to ensure the hardware can be upgraded. Keep in mind there is an actual physical chip in the hardware that would need to support both AS2 and AS3.</p>
<p> </p>
<h3>Conclusion</h3>
<p>Are there scenerios that I haven't outlined? Of course. The three above are my 'best guesses.' What can we expect from MAX 2009? Hopefully some awesome news about Flash for your TV!</p>
<p>Whether it launches in AS2 or AS3, Flash support for televisions will be very cool. You may want to brush up on your ActionScript 2 skills just in case <img src='http://www.blackcj.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>*Disclaimer*</strong><br />
<em>While it should be obvious, this post is entirely speculation. Adobe has remained completely silent on the topic of Flash for your TV, if anything, a bit too silent. The goal of this post is to get people thinking about the topic so they are ready when the hardware is available.</em></p>
<p><strong>Resources</strong><br />
<a href="http://www.engadgethd.com/tag/ce+3100/" target="_blank">Engagethd</a><br />
<a href="http://www.broadcom.com/press/release.php?id=s357665" target="_blank">Broadcom - Press Release</a><br />
<a href="http://www.adobe.com/aboutadobe/pressroom/pressreleases/200901/010509IntelAdobePR.html">Adobe - Press Release</a><br />
<a href="http://nerdacumen.com/white-paper-adobe-flash-for-television/2009/08/26/" target="_blank">Nerd Acumen</a><br />
<a href="http://www.twitter.com/flashyourtv" target="_blank">Flash Your TV on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2009/09/08/flash-your-tv-the-suspense-is-killing-me/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Box2D Part 3: Anti-Gravity</title>
		<link>http://www.blackcj.com/blog/2009/08/17/box2d-part-3-anti-gravity/</link>
		<comments>http://www.blackcj.com/blog/2009/08/17/box2d-part-3-anti-gravity/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 02:04:43 +0000</pubDate>
		<dc:creator>Chris Black</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Box2d]]></category>

		<guid isPermaLink="false">http://www.blackcj.com/blog/?p=501</guid>
		<description><![CDATA[Can you get the objects to float in space using your mouse?  This is the conclusion to the three part series on using the Box2D Physics engine with ActionScript.
Box2D Anti-Gravity Example:

var flashvars = {}; var params = { bgcolor: "ffffff" }; swfobject.embedSWF("http://www.blackcj.com/blog/wp-content/swfs/Box2DQuickStart/Box2DQuickStart.swf", "Box2DQuickStart", "440", "340", "9.0.0", "flash/expressInstall.swf", flashvars, params);


Box2D Anti-Gravity Example

(click and hold the [...]]]></description>
			<content:encoded><![CDATA[<p>Can you get the objects to float in space using your mouse?  This is the conclusion to the three part series on using the Box2D Physics engine with ActionScript.</p>
<h3>Box2D Anti-Gravity Example:</h3>
<p><script type="text/javascript">
var flashvars = {}; var params = { bgcolor: "ffffff" }; swfobject.embedSWF("http://www.blackcj.com/blog/wp-content/swfs/Box2DQuickStart/Box2DQuickStart.swf", "Box2DQuickStart", "440", "340", "9.0.0", "flash/expressInstall.swf", flashvars, params);
</script></p>
<div id="Box2DQuickStart">
<h1>Box2D Anti-Gravity Example</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>
<p><em>(click and hold the mouse down for anti-gravity)</em></p>
<p>Now that we have a Box2D environment set up and lots of polygons in it, let's make it cool.</p>
<p><strong>Anti-gravity boolean.</strong><br />
Add this boolean and if statement into your shape environment class.</p>
<div class="igBar"><span id="lactionscript-29"><a href="#" onclick="javascript:showPlainTxt('actionscript-29'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-29">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> counterGravity:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">override protected <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// ...(from part 2)... //</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>bb.<span style="color: #006600;">m_userData</span> is Sprite<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>counterGravity<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; world.<span style="color: #006600;">SetGravity</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> b2Vec2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>,-<span style="color: #cc66cc;color:#800000;">9</span>.<span style="color: #cc66cc;color:#800000;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bb.<span style="color: #006600;">WakeUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; world.<span style="color: #006600;">SetGravity</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> b2Vec2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>,<span style="color: #cc66cc;color:#800000;">9</span>.<span style="color: #cc66cc;color:#800000;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// ...(from part 2)... // </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now add a mouse event handler and the following functions into your main class.</p>
<div class="igBar"><span id="lactionscript-30"><a href="#" onclick="javascript:showPlainTxt('actionscript-30'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-30">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> addCounterGravity<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; _shape2d.<span style="color: #006600;">counterGravity</span> = <span style="color: #000000; font-weight: bold;">true</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> removeCounterGravity<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; _shape2d.<span style="color: #006600;">counterGravity</span> = <span style="color: #000000; font-weight: bold;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now you have anti-gravity!</p>
<p>Miss out on the basics? Check out <a href="http://www.blackcj.com/blog/2009/08/17/box2d-part-1-its-a-small-world/">part 1</a> and <a href="http://www.blackcj.com/blog/2009/08/17/box2d-part-2-shape-factory/">part 2</a> of this series.</p>
<p>Full source code <a href="http://www.blackcj.com/blog/wp-content/swfs/Box2DQuickStart/srcview/index.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blackcj.com/blog/2009/08/17/box2d-part-3-anti-gravity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.818 seconds -->
<!-- Cached page served by WP-Cache -->
