<?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>circlecube &#187; tutorial</title>
	<atom:link href="http://blog.circlecube.com/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.circlecube.com</link>
	<description>Evan&#039;s Interactive Actionscript Exploration</description>
	<lastBuildDate>Wed, 14 Jul 2010 17:30:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Better jquery mega-menu tutorial</title>
		<link>http://blog.circlecube.com/2010/07/tutorial/better-jquery-mega-menu-tutorial/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=better-jquery-mega-menu-tutorial</link>
		<comments>http://blog.circlecube.com/2010/07/tutorial/better-jquery-mega-menu-tutorial/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 17:30:03 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[abstract]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[ux]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=1295</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2010/07/tutorial/better-jquery-mega-menu-tutorial/"><img align="left" hspace="5" width="150" height="150" src="http://blog.circlecube.com/wp-content/uploads/2010/07/better-mega-menu-screenshot-150x150.png" class="alignleft tfe wp-post-image" alt="better-mega-menu-screenshot" title="better-mega-menu-screenshot" /></a>My earlier simple mega menu implementation post displayed some simple css and jquery to explode a standard navigation menu into a mega-menu&#8230; I&#8217;ve made it even better. My biggest issue with that implementation was that it did not keep the order like you&#8217;d expect. It read left to right in columns rather than down each [...]]]></description>
			<content:encoded><![CDATA[<p>My earlier <a href="http://blog.circlecube.com/2010/07/tutorial/a-simple-mega-menu-implementation/">simple mega menu implementation</a> post displayed some simple css and jquery to explode a standard navigation menu into a mega-menu&#8230; I&#8217;ve made it even better. My biggest issue with that implementation was that it did not keep the order like you&#8217;d expect. It read left to right in columns rather than down each column. In the example you can see the first column of three would read from the top: a, d, g, j&#8230; this could potentially be confusing. So I wanted to update it to keep the order better and just stack the columns of elements rather than the elements themselves.</p>
<p>I used some different jquery to execute this. First we walk through the menu elements and calculate which column they should be in. We basically map that element&#8217;s (li)index to the column it should be, some big math. Luckily I had some experience from actionscript in my arsenal doing just that, so porting the function to javascript I was ready to go. If your number X falls between A and B, and you would like to convert it to Y which falls between C and D follow this formula: Y = (X-A)/(B-A) * (D-C) + C. Plugging this function in and cancelling out the zeros and adding some rounding to get integers I got: Math.floor((liindex / $total * $cols)+1). Using this I added a class to each &#8216;li&#8217; designating which column it should be in, and then used wrapAll to wrap them into column divs. Very simple and a much better implementation overall anyways. Better code, better user experience&#8230; what more can you ask&#8230; so here&#8217;s the example and jquery code. I&#8217;m thinking I should make this into a jquery plugin or something, any thoughts?</p>
<p><img src="http://blog.circlecube.com/wp-content/uploads/2010/07/better-mega-menu-screenshot.png" alt="better-mega-menu-screenshot" title="better-mega-menu-screenshot" width="550" height="166" class="aligncenter size-full wp-image-1299" /></p>
<h3><a href="http://blog.circlecube.com/wp-content/uploads/2010/07/mega-menu-columns-demo.html" target="_blank">See the mega menu in action</a></h3>
<h3>Javascript code</h3>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//clean up the row of the mega menu. add css class to each element on bottom row.</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//only if more than 7 elements. if more than 16, mm-3</span><br />
&nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nav li ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ulindex<span style="color: #339933;">,</span> ulele<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $total <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$total <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mm-1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $cols <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$total<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $remainder <span style="color: #339933;">=</span> $total <span style="color: #339933;">%</span> $cols<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $rows <span style="color: #339933;">=</span> Math.<span style="color: #660066;">ceil</span><span style="color: #009900;">&#40;</span>$total <span style="color: #339933;">/</span> $cols<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mm-'</span> <span style="color: #339933;">+</span> $cols <span style="color: #339933;">+</span> <span style="color: #3366CC;">' total-'</span> <span style="color: #339933;">+</span> $total <span style="color: #339933;">+</span> <span style="color: #3366CC;">' rem-'</span><span style="color: #339933;">+</span>$remainder <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>liindex<span style="color: #339933;">,</span> liele<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//alert(&quot;total: &quot;+$total+&quot;, remainder: &quot;+ $mod+&quot;, ulindex: &quot;+ulindex+&quot;, liindex: &quot;+liindex);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//If your number X falls between A and B, and you would like to convert it to Y which falls between C and D follow this formula: Y = (X-A)/(B-A) * (D-C) + C.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'col-'</span> <span style="color: #339933;">+</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>liindex <span style="color: #339933;">/</span> $total <span style="color: #339933;">*</span> $cols<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>liindex<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> $rows <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'last'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> colcount <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> colcount<span style="color: #339933;">&lt;=</span> $cols<span style="color: #339933;">;</span> colcount<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.col-'</span><span style="color: #339933;">+</span>colcount<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">wrapAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;col&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h3>css</h3>
<div class="codecolorer-container css mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/********** &lt; Navigation */</span><br />
<span style="color: #6666ff;">.nav-container</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#398301</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">960px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #933;">44px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">13px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* All Levels */</span><br />
<span style="color: #cc00cc;">#nav</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">999</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.parent</span> <span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a span <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span><span style="color: #993333;">nowrap</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li ul a span <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* 1st Level */</span><br />
<span style="color: #cc00cc;">#nav</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#1b3f00</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> a<span style="color: #00AA00;">,</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.active</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* 2nd Level */</span><br />
<span style="color: #cc00cc;">#nav</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">15em</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">26px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-10000px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#1b3f00</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1px</span> <span style="color: #933;">2px</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#398301</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">6px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">6px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul div<span style="color: #6666ff;">.col</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">6px</span> <span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFF</span> !important<span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#1b3f00</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#1b3f00</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#398301</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span> !important<span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#2b6301</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li<span style="color: #6666ff;">.last</span> <span style="color: #00AA00;">&gt;</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li<span style="color: #6666ff;">.last</span><span style="color: #6666ff;">.parent</span> <span style="color: #00AA00;">&gt;</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #cc00cc;">#nav</span> ul li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&gt;</span> a &nbsp;<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span> !important<span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#1b3f00</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul<span style="color: #6666ff;">.mm-1</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul<span style="color: #6666ff;">.mm-2</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul<span style="color: #6666ff;">.mm-3</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">45em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul<span style="color: #6666ff;">.mm-4</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">/* 3rd+ leven */</span><br />
<span style="color: #cc00cc;">#nav</span> ul ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">-6px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#1b3f00</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* Show Menu - uses built-in magento menu hovering */</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&gt;</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&gt;</span> ul li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&gt;</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">14em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> ul ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-10000px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* Show Menu - uses css only, not fully across all browsers but, for the purpose of the demo is fine by me */</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&gt;</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&gt;</span> ul li<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&gt;</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">14em</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">200</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #3333ff;">:hover </span>ul ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-10000px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<h3>Download</h3>
<p><a href="http://blog.circlecube.com/wp-content/uploads/2010/07/mega-menu-columns-demo.html" target="_blank" title="Mega Menu with Columns from css and jQuery Demo">Visit this demo page and view source or save as&#8230;</a></p>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F&amp;title=Better%20jquery%20mega-menu%20tutorial&amp;notes=My%20earlier%20simple%20mega%20menu%20implementation%20post%20displayed%20some%20simple%20css%20and%20jquery%20to%20explode%20a%20standard%20navigation%20menu%20into%20a%20mega-menu...%20I%27ve%20made%20it%20even%20better.%20My%20biggest%20issue%20with%20that%20implementation%20was%20that%20it%20did%20not%20keep%20the%20order%20like" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F&amp;title=Better%20jquery%20mega-menu%20tutorial&amp;bodytext=My%20earlier%20simple%20mega%20menu%20implementation%20post%20displayed%20some%20simple%20css%20and%20jquery%20to%20explode%20a%20standard%20navigation%20menu%20into%20a%20mega-menu...%20I%27ve%20made%20it%20even%20better.%20My%20biggest%20issue%20with%20that%20implementation%20was%20that%20it%20did%20not%20keep%20the%20order%20like" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Better%20jquery%20mega-menu%20tutorial&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F&amp;t=Better%20jquery%20mega-menu%20tutorial" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F&amp;title=Better%20jquery%20mega-menu%20tutorial&amp;annotation=My%20earlier%20simple%20mega%20menu%20implementation%20post%20displayed%20some%20simple%20css%20and%20jquery%20to%20explode%20a%20standard%20navigation%20menu%20into%20a%20mega-menu...%20I%27ve%20made%20it%20even%20better.%20My%20biggest%20issue%20with%20that%20implementation%20was%20that%20it%20did%20not%20keep%20the%20order%20like" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F&amp;title=Better%20jquery%20mega-menu%20tutorial&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=My%20earlier%20simple%20mega%20menu%20implementation%20post%20displayed%20some%20simple%20css%20and%20jquery%20to%20explode%20a%20standard%20navigation%20menu%20into%20a%20mega-menu...%20I%27ve%20made%20it%20even%20better.%20My%20biggest%20issue%20with%20that%20implementation%20was%20that%20it%20did%20not%20keep%20the%20order%20like" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F&amp;title=Better%20jquery%20mega-menu%20tutorial" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F&amp;title=Better%20jquery%20mega-menu%20tutorial" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Better%20jquery%20mega-menu%20tutorial%20-%20http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fbetter-jquery-mega-menu-tutorial%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2010/07/tutorial/better-jquery-mega-menu-tutorial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A simple mega menu implementation with CSS and jquery</title>
		<link>http://blog.circlecube.com/2010/07/tutorial/a-simple-mega-menu-implementation/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=a-simple-mega-menu-implementation</link>
		<comments>http://blog.circlecube.com/2010/07/tutorial/a-simple-mega-menu-implementation/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 18:26:23 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[abstract]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[ux]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=1283</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2010/07/tutorial/a-simple-mega-menu-implementation/"><img align="left" hspace="5" width="150" height="150" src="http://blog.circlecube.com/wp-content/uploads/2010/07/mega-menu-screenshot-150x150.jpg" class="alignleft tfe wp-post-image" alt="mega-menu-screenshot" title="mega-menu-screenshot" /></a>I&#8217;ve been skinning quite a few ecommerce sites with the magento platform and wanted a simple way to explode the navigation menus. Some sites end up getting a long list of categories and sub-categories, so I wanted to do a mega-menu style navigation. One way to do it was to rewrite the html code for [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been skinning quite a few ecommerce sites with the magento platform and wanted a simple way to explode the navigation menus. Some sites end up getting a long list of categories and sub-categories, so I wanted to do a mega-menu style navigation. One way to do it was to rewrite the html code for the navigation and pop each column into another nested unordered list. I&#8217;m not a fan of doing this because one &#8211; I didn&#8217;t want to manipulate the html. I like the simplicity of ul navigation with a clear flat list of li elements. Of course for nested sub-navigation any li can contain another ul. I wanted to just use some css and maybe javascript to visually accomplish the same thing. I also wanted it to be portable, so I could take it and use it on a wordpress install or even a plain html site. I went to my favorite: jquery. I knew there was a likely plugin out there already that would do something similar, but nothing after my initial search, but I realized that it was a simple procedure and mostly accomplished with some css.<br />
<img src="http://blog.circlecube.com/wp-content/uploads/2010/07/mega-menu-screenshot.jpg" alt="mega menu screenshot" title="mega-menu-screenshot" width="550" height="221" class="aligncenter size-full wp-image-1288" /><br />
I&#8217;ll walk you through the process here and let you inspect the code yourself and see it in action on the demo page. Assign each ul to be a default width of 15em, then each li element we float:left and also give it a width of 15em. This way we can change the ul width to 30em and automatically I have 2 columns! Assigning the nested ul a specific width according to it&#8217;s class is done through css, mm-0 will be 15em and incrementally each next one will be 15em more. mm-1 is 30 and mm-2 is 45. Then we use jquery to determine the number of elements in the list and assign it a class accordingly. This involves some math and some preferences. Using the magic ui number 7, I determined that a menu with more than 7 elements should explode into multiple columns. So anything less than or equal to 7 I assign the class &#8216;mm-1&#8242; which in the css sets the width to the standard 15em (ie 1 mega menu column). More than 7 should pop into columns no more than 8 tall. So dividing the total by 8 will give us the number of columns we want. We&#8217;ll add a class of mm-x, where x would be the number of columns. And the li elements will float to the left and fill in the space in columns.<br />
One specific issue is the last element in the menu, sometimes we need to style that element differently. I&#8217;ll loop through each child of the nested ul element and if it is on the bottom row apply a class of &#8216;last&#8217;. But this was a little tricky in calculating which would be last because were never sure how many elements there will be or how many columns. I just used the remainder after dividing the total by the number of columns, then if the remainder could be used to know which elements are on the bottom row.</p>
<p>OK, now that that&#8217;s out of the way, let&#8217;s look at the code.</p>
<h3>HTML</h3>
<p>This I won&#8217;t show, you can inspect the source of the demo if you wish to see it, it a basic nested collection of unordered lists. It&#8217;s the standard that is created by magento, wordpress and most other CMS platforms.</p>
<h3>CSS</h3>
<div class="codecolorer-container css mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">html<span style="color: #00AA00;">,</span> body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/********** &lt; Navigation */</span><br />
<span style="color: #6666ff;">.nav-container</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#186C94</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">960px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #933;">44px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">13px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* All Levels */</span><br />
<span style="color: #cc00cc;">#nav</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">999</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.parent</span> <span style="color: #00AA00;">&#123;</span><span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a span <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span><span style="color: #993333;">nowrap</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li ul a span <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* 1st Level */</span><br />
<span style="color: #cc00cc;">#nav</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#111</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> a<span style="color: #00AA00;">,</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.active</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* 2nd Level */</span><br />
<span style="color: #cc00cc;">#nav</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">15em</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">26px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-10000px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#104A65</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1px</span> <span style="color: #933;">2px</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#186C94</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">6px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">6px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul div<span style="color: #6666ff;">.col</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">6px</span> <span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFF</span> !important<span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#111</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#104A65</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#186C94</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span> !important<span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#135575</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li<span style="color: #6666ff;">.last</span> <span style="color: #00AA00;">&gt;</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul li<span style="color: #6666ff;">.last</span><span style="color: #6666ff;">.parent</span> <span style="color: #00AA00;">&gt;</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #cc00cc;">#nav</span> ul li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&gt;</span> a &nbsp;<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span> !important<span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#104A65</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul<span style="color: #6666ff;">.mm-1</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul<span style="color: #6666ff;">.mm-2</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul<span style="color: #6666ff;">.mm-3</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">45em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> ul<span style="color: #6666ff;">.mm-4</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">/* 3rd+ leven */</span><br />
<span style="color: #cc00cc;">#nav</span> ul ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">-6px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#104A65</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* Show Menu - uses built-in magento menu hovering */</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&gt;</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&gt;</span> ul li<span style="color: #6666ff;">.over</span> <span style="color: #00AA00;">&gt;</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">14em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #6666ff;">.over</span> ul ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-10000px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* Show Menu - uses css only, not fully across all browsers but, for the purpose of the demo is fine by me */</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&gt;</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&gt;</span> ul li<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&gt;</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">14em</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">200</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span><br />
<span style="color: #cc00cc;">#nav</span> li<span style="color: #3333ff;">:hover </span>ul ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-10000px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<h3>Javascript</h3>
<p>Don&#8217;t forget to include jQuery (I prefer using the google hosted version at http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js)</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//clean up the row of the mega menu. add css class to each element on bottom row.</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//only if more than 7 elements. if more than 16, mm-3</span><br />
&nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nav li ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ulindex<span style="color: #339933;">,</span> ulele<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $total <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$total <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mm-1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $cols <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>$total<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $remainder <span style="color: #339933;">=</span> $total <span style="color: #339933;">%</span> $cols<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mm-'</span> <span style="color: #339933;">+</span> $cols <span style="color: #339933;">+</span> <span style="color: #3366CC;">' total-'</span> <span style="color: #339933;">+</span> $total <span style="color: #339933;">+</span> <span style="color: #3366CC;">' rem-'</span><span style="color: #339933;">+</span>$remainder <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>liindex<span style="color: #339933;">,</span> liele<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//alert(&quot;total: &quot;+$total+&quot;, remainder: &quot;+ $mod+&quot;, ulindex: &quot;+ulindex+&quot;, liindex: &quot;+liindex);&nbsp; &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> liindex <span style="color: #339933;">+</span> $remainder <span style="color: #339933;">&gt;=</span> $total <span style="color: #339933;">||</span> $remainder <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">&amp;&amp;</span> liindex <span style="color: #339933;">+</span> $cols <span style="color: #339933;">&gt;=</span> $total <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//alert(&quot;total: &quot;+$total+&quot;, remainder: &quot;+ $remainder+&quot;, index: &quot;+liindex);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'last'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h3><a href="http://blog.circlecube.com/wp-content/uploads/2010/07/mega-menu-demo.html" target="_blank" title="don't forget to view source">See the demo in action</a></h3>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F&amp;title=A%20simple%20mega%20menu%20implementation%20with%20CSS%20and%20jquery&amp;notes=I%27ve%20been%20skinning%20quite%20a%20few%20ecommerce%20sites%20with%20the%20magento%20platform%20and%20wanted%20a%20simple%20way%20to%20explode%20the%20navigation%20menus.%20Some%20sites%20end%20up%20getting%20a%20long%20list%20of%20categories%20and%20sub-categories%2C%20so%20I%20wanted%20to%20do%20a%20mega-menu%20style%20navigation.%20" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F&amp;title=A%20simple%20mega%20menu%20implementation%20with%20CSS%20and%20jquery&amp;bodytext=I%27ve%20been%20skinning%20quite%20a%20few%20ecommerce%20sites%20with%20the%20magento%20platform%20and%20wanted%20a%20simple%20way%20to%20explode%20the%20navigation%20menus.%20Some%20sites%20end%20up%20getting%20a%20long%20list%20of%20categories%20and%20sub-categories%2C%20so%20I%20wanted%20to%20do%20a%20mega-menu%20style%20navigation.%20" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=A%20simple%20mega%20menu%20implementation%20with%20CSS%20and%20jquery&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F&amp;t=A%20simple%20mega%20menu%20implementation%20with%20CSS%20and%20jquery" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F&amp;title=A%20simple%20mega%20menu%20implementation%20with%20CSS%20and%20jquery&amp;annotation=I%27ve%20been%20skinning%20quite%20a%20few%20ecommerce%20sites%20with%20the%20magento%20platform%20and%20wanted%20a%20simple%20way%20to%20explode%20the%20navigation%20menus.%20Some%20sites%20end%20up%20getting%20a%20long%20list%20of%20categories%20and%20sub-categories%2C%20so%20I%20wanted%20to%20do%20a%20mega-menu%20style%20navigation.%20" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F&amp;title=A%20simple%20mega%20menu%20implementation%20with%20CSS%20and%20jquery&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=I%27ve%20been%20skinning%20quite%20a%20few%20ecommerce%20sites%20with%20the%20magento%20platform%20and%20wanted%20a%20simple%20way%20to%20explode%20the%20navigation%20menus.%20Some%20sites%20end%20up%20getting%20a%20long%20list%20of%20categories%20and%20sub-categories%2C%20so%20I%20wanted%20to%20do%20a%20mega-menu%20style%20navigation.%20" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F&amp;title=A%20simple%20mega%20menu%20implementation%20with%20CSS%20and%20jquery" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F&amp;title=A%20simple%20mega%20menu%20implementation%20with%20CSS%20and%20jquery" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=A%20simple%20mega%20menu%20implementation%20with%20CSS%20and%20jquery%20-%20http%3A%2F%2Fblog.circlecube.com%2F2010%2F07%2Ftutorial%2Fa-simple-mega-menu-implementation%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2010/07/tutorial/a-simple-mega-menu-implementation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Flashvars and as3</title>
		<link>http://blog.circlecube.com/2009/12/tutorial/flashvars-and-as3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=flashvars-and-as3</link>
		<comments>http://blog.circlecube.com/2009/12/tutorial/flashvars-and-as3/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 00:27:37 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=668</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2009/12/tutorial/flashvars-and-as3/"><img align="left" hspace="5" width="150" src="http://blog.circlecube.com/wp-content/uploads/2009/12/flashvars_as3_thumb-150x150.png" class="alignleft wp-post-image tfe" alt="flashvars_as3_thumb" title="flashvars_as3_thumb" /></a>Flashvars and actionscript 3! Flashvar is a way that in your html embed codes (object tags) you can send variables and values into your swf file. These variables can then be grabbed internally and used your programming! Examples of these could be images that you want to use in your swf but don&#8217;t want to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.circlecube.com/wp-content/uploads/2009/12/flashvars_as3_thumb-150x150.png" alt="flashvars_as3_thumb" title="flashvars_as3_thumb" width="150" height="150" class="alignleft size-thumbnail wp-image-1236" />Flashvars and actionscript 3! Flashvar is a way that in your html embed codes (object tags) you can send variables and values into your swf file. These variables can then be grabbed internally and used your programming! Examples of these could be images that you want to use in your swf but don&#8217;t want to import or hardcode them into the flash file or paths to xml or flv files to use as well. Actionscript 3 has a different procedure than as2 did as to how you read these flashvars from the actionscript side. The embed codes and html side of things are still the same, but in case your new to actionscript altogether, I&#8217;ll give an example of the html as well.</p>
<div class="codecolorer-container html4strict mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">object</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">data</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flashvars_as3.swf&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flashvars&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;colors=0x012345,0x123456,0x234567,0x345678,0x456789,0x567890,0x678901,0x789012&amp;delay=.11&amp;loop=true&amp;random=false&quot;</span><span style="color: #66cc66;">/</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">object</span>&gt;</span></div></td></tr></tbody></table></div>
<p>In actionscript 3 we use the loaderInfo object to access the flashvars. The parameters Object of the loaderInfo will contain all the flashvar variables and values.</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">this</span>.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span></div></td></tr></tbody></table></div>
<p>As an example of something that is visual I&#8217;ve created this little app to read some options from flashvars about colors. An app that will read a list of colors and update a box that is on the stage already to those colors with the specified delay. I always have fun with randomness so I threw in the option for random colors as well. This file looks for certain flashvars: color, loop, delay and random. These are the keys or names of the variables and they are followed by the values you want them to hold. Note that flashvars can be set in any order, so you don&#8217;t have to start with color and end with random.</p>
<p>In this example I&#8217;m looking for 4 flashvars specifically (in any order):</p>
<ul>
<li>colors:String &#8211; a comma delimited list of hex colors or simply a string &#8220;random&#8221; for randomly generated colors (the hex for black #000000 needs to be 0&#215;000000 in flash) (default is random)</li>
<li>loop:Boolean &#8211; whether or not to repeat these colors (default is true)</li>
<li>delay:Number &#8211; the delay between colors (in seconds). (default is 1 second)</li>
<li>random:Boolean &#8211; determines whether to cycle through colors in given order or randomize. selecting random overrides the loop to true. (default is false)</li>
</ul>
<p>This is much more than is required for this example, but I was having fun playing with random colors and timing and options. I figured it diesn&#8217;t hurt to show the effect you can have with a couple different variables on one file. Here is an example using the object tags above:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_flashvars_as3_1842182831"
			class="flashmovie"
			width="200"
			height="200">
	<param name="movie" value="http://blog.circlecube.com/wp-content/uploads/2009/12/flashvars_as3.swf" />
	<param name="flashvars" value="colors=0xFF0000,0x0FF000,0x00FF00,0x000FF0,0X0000FF,0xF0000F&#038&amp;delay=.66&#038&amp;loop=true&#038&amp;random=false" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.circlecube.com/wp-content/uploads/2009/12/flashvars_as3.swf"
			name="fm_flashvars_as3_1842182831"
			width="200"
			height="200">
		<param name="flashvars" value="colors=0xFF0000,0x0FF000,0x00FF00,0x000FF0,0X0000FF,0xF0000F&#038&amp;delay=.66&#038&amp;loop=true&#038&amp;random=false" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><a href="http://blog.circlecube.com/wp-content/uploads/2009/12/flashvars_as3.html">And here are some more (please don&#8217;t have a seizure!)</a></p>
<p>Here&#8217;s the full source if you&#8217;re interested:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/*<br />
circlecube.com<br />
<br />
App to demonstrate the process of getting flashvars from embed code to actionscript (as3)<br />
<br />
Displays colors specified.<br />
<br />
looking for 4 flashvars specifically (in any order):<br />
colors:String - a comma delimited list of hex colors or simply a string &quot;random&quot; for randomly generated colors (the hex for black #000000 needs to be 0x000000) (default is random)<br />
loop:Boolean - wether or not to repeat these colors (default is true)<br />
delay:Number - the delay between colors (in seconds). (default is 1 second)<br />
random:Boolean - determines wether to cycle through colors in given order or randomize. selecting random overrides the loop to true. (default is false)<br />
<br />
*/</span><br />
<br />
<span style="color: #808080; font-style: italic;">//initialize vars</span><br />
<span style="color: #000000; font-weight: bold;">var</span> myflashvars:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">var</span> myColors:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;random&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> myLoop:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> myDelay:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> randomOrder:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> allRandom:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
<span style="color: #808080; font-style: italic;">//read flashvars in actionscript3</span><br />
<span style="color: #808080; font-style: italic;">//if colors flashvars doesn't exist use these defaults </span><br />
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">colors</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span> <br />
&nbsp; &nbsp; myflashvars = <span style="color: #66cc66;">&#123;</span>colors: <span style="color: #ff0000;">&quot;random&quot;</span>, delay: <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#125;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; myflashvars = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//assign flashvars to variables within flash</span><br />
<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> item:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> myflashvars<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>item + <span style="color: #ff0000;">&quot;:<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> + myflashvars<span style="color: #66cc66;">&#91;</span>item<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>item == <span style="color: #ff0000;">&quot;colors&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myColors = myflashvars<span style="color: #66cc66;">&#91;</span>item<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">','</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>item == <span style="color: #ff0000;">&quot;loop&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myLoop = parseBoolean<span style="color: #66cc66;">&#40;</span>myflashvars<span style="color: #66cc66;">&#91;</span>item<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>item == <span style="color: #ff0000;">&quot;delay&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; myDelay = myflashvars<span style="color: #66cc66;">&#91;</span>item<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>item == <span style="color: #ff0000;">&quot;random&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; randomOrder = parseBoolean<span style="color: #66cc66;">&#40;</span>myflashvars<span style="color: #66cc66;">&#91;</span>item<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">//use my variables!</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>myColors<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #ff0000;">&quot;random&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; allRandom = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">var</span> counter:Timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span>myDelay <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>;<br />
counter.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, nextColor<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">trace</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;color number: 0&quot;</span>, <span style="color: #ff0000;">&quot;color hex: &quot;</span>+myColors<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
setColor<span style="color: #66cc66;">&#40;</span>myBox, myColors<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
counter.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">function</span> nextColor<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><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//cycle through colors</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>allRandom <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #66cc66;">!</span>randomOrder<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>counter.<span style="color: #006600;">currentCount</span>+<span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&gt;</span> myColors.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>myLoop == <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">||</span> myLoop == <span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter.<span style="color: #006600;">reset</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;color number: &quot;</span>+counter.<span style="color: #006600;">currentCount</span>, <span style="color: #ff0000;">&quot;color hex: &quot;</span>+myColors<span style="color: #66cc66;">&#91;</span>counter.<span style="color: #006600;">currentCount</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; setColor<span style="color: #66cc66;">&#40;</span>myBox, myColors<span style="color: #66cc66;">&#91;</span>counter.<span style="color: #006600;">currentCount</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//randomly select a color from the myColors array</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>allRandom <span style="color: #66cc66;">&amp;&amp;</span> randomOrder<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> randomColor = <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: #66cc66;">*</span> myColors.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;random number: &quot;</span>+randomColor, <span style="color: #ff0000;">&quot;color hex: &quot;</span>+myColors<span style="color: #66cc66;">&#91;</span>randomColor<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; setColor<span style="color: #66cc66;">&#40;</span>myBox, myColors<span style="color: #66cc66;">&#91;</span>randomColor<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//randomly create colors</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;number: &quot;</span>+counter.<span style="color: #006600;">currentCount</span>, <span style="color: #ff0000;">&quot;color hex: &quot;</span>+myColors<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; setColor<span style="color: #66cc66;">&#40;</span>myBox, myColors<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> setColor<span style="color: #66cc66;">&#40;</span>item:DisplayObject, col<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>col == <span style="color: #ff0000;">&quot;random&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; setRandomColor<span style="color: #66cc66;">&#40;</span>item<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; setHexColor<span style="color: #66cc66;">&#40;</span>item, col<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> setHexColor<span style="color: #66cc66;">&#40;</span>item:DisplayObject, col:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> myColor:ColorTransform &nbsp;= &nbsp;item.<span style="color: #006600;">transform</span>.<span style="color: #006600;">colorTransform</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//check color bounds</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>col <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">16777215</span><span style="color: #66cc66;">&#41;</span> col = <span style="color: #cc66cc;">16777215</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>col <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> col = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; myColor.<span style="color: #0066CC;">color</span> = col;<br />
&nbsp; &nbsp; item.<span style="color: #006600;">transform</span>.<span style="color: #006600;">colorTransform</span> = myColor;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> setRandomColor<span style="color: #66cc66;">&#40;</span>item:DisplayObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; setColor<span style="color: #66cc66;">&#40;</span>item, <span style="color: #66cc66;">&#40;</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: #66cc66;">*</span> <span style="color: #cc66cc;">16777215</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> parseBoolean<span style="color: #66cc66;">&#40;</span>str:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span>str.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Check for true values</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;1&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;true&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;yes&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Check for false values</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;0&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;false&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;no&quot;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// If all else fails cast string</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">default</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#40;</span>str<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F&amp;title=Flashvars%20and%20as3&amp;notes=Flashvars%20and%20actionscript%203%21%20Flashvar%20is%20a%20way%20that%20in%20your%20html%20embed%20codes%20%28object%20tags%29%20you%20can%20send%20variables%20and%20values%20into%20your%20swf%20file.%20These%20variables%20can%20then%20be%20grabbed%20internally%20and%20used%20your%20programming%21%20Examples%20of%20these%20could%20be%20ima" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F&amp;title=Flashvars%20and%20as3&amp;bodytext=Flashvars%20and%20actionscript%203%21%20Flashvar%20is%20a%20way%20that%20in%20your%20html%20embed%20codes%20%28object%20tags%29%20you%20can%20send%20variables%20and%20values%20into%20your%20swf%20file.%20These%20variables%20can%20then%20be%20grabbed%20internally%20and%20used%20your%20programming%21%20Examples%20of%20these%20could%20be%20ima" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Flashvars%20and%20as3&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F&amp;t=Flashvars%20and%20as3" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F&amp;title=Flashvars%20and%20as3&amp;annotation=Flashvars%20and%20actionscript%203%21%20Flashvar%20is%20a%20way%20that%20in%20your%20html%20embed%20codes%20%28object%20tags%29%20you%20can%20send%20variables%20and%20values%20into%20your%20swf%20file.%20These%20variables%20can%20then%20be%20grabbed%20internally%20and%20used%20your%20programming%21%20Examples%20of%20these%20could%20be%20ima" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F&amp;title=Flashvars%20and%20as3&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=Flashvars%20and%20actionscript%203%21%20Flashvar%20is%20a%20way%20that%20in%20your%20html%20embed%20codes%20%28object%20tags%29%20you%20can%20send%20variables%20and%20values%20into%20your%20swf%20file.%20These%20variables%20can%20then%20be%20grabbed%20internally%20and%20used%20your%20programming%21%20Examples%20of%20these%20could%20be%20ima" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F&amp;title=Flashvars%20and%20as3" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F&amp;title=Flashvars%20and%20as3" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Flashvars%20and%20as3%20-%20http%3A%2F%2Fblog.circlecube.com%2F2009%2F12%2Ftutorial%2Fflashvars-and-as3%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2009/12/tutorial/flashvars-and-as3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tutorial to Create a Responsive Image Scroller in ActionScript 3.0</title>
		<link>http://blog.circlecube.com/2009/08/tutorial/tutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=tutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0</link>
		<comments>http://blog.circlecube.com/2009/08/tutorial/tutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 18:55:02 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[portfolio]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=1212</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2009/08/tutorial/tutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0/"><img align="left" hspace="5" width="150" src="http://blog.circlecube.com/wp-content/uploads/2009/08/responsive-images-scroller-as3-thumb-150x150.jpg" class="alignleft wp-post-image tfe" alt="responsive-images-scroller-as3-thumb" title="responsive-images-scroller-as3-thumb" /></a>I&#8217;ve written a tutorial which is published over at flash.tutsplus. This tutorial demonstrates how to create a horizontally scrolling image viewer and covers xml parsing, loading and resizing external images, and creating intuitive and responsive scrolling! 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_image-scroller-example_1913491470"
			class="flashmovie"
			width="550"
			height="137">
	<param name="movie" value="http://blog.circlecube.com/wp-content/uploads/2009/07/image-scroller-example.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.circlecube.com/wp-content/uploads/2009/07/image-scroller-example.swf"
			name="fm_image-scroller-example_1913491470"
			width="550"
			height="137">
	<!--<![endif]-->
		 
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object> So check out the Tutorial to Create a Responsive Image Scroller [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.circlecube.com/wp-content/uploads/2009/08/responsive-images-scroller-as3-thumb-150x150.jpg" alt="responsive-images-scroller-as3-thumb" title="responsive-images-scroller-as3-thumb" width="150" height="150" class="alignleft size-thumbnail wp-image-1213" /></p>
<p>I&#8217;ve written a tutorial which is published over at flash.tutsplus. This tutorial demonstrates how to create a horizontally scrolling image viewer and covers xml parsing, loading and resizing external images, and creating intuitive and responsive scrolling!</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_image-scroller-example_742953696"
			class="flashmovie"
			width="550"
			height="137">
	<param name="movie" value="http://blog.circlecube.com/wp-content/uploads/2009/07/image-scroller-example.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.circlecube.com/wp-content/uploads/2009/07/image-scroller-example.swf"
			name="fm_image-scroller-example_742953696"
			width="550"
			height="137">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<h3>So check out the <a href="http://active.tutsplus.com/tutorials/xml/create-a-responsive-xml-image-scroller-in-actionscript-3-0/">Tutorial to Create a Responsive Image Scroller in ActionScript 3.0</a> over at flash.tutsplus.com!</h3>
<p><a href="http://active.tutsplus.com/tutorials/xml/create-a-responsive-xml-image-scroller-in-actionscript-3-0/"><img src="http://flashtuts.s3.amazonaws.com/source.jpg" alt="source" width="160" height="50" class="alignleft" /><img src="http://flashtuts.s3.amazonaws.com/demo.jpg" alt="demo" width="160" height="50" class="alignleft" /><img src="http://flashtuts.s3.amazonaws.com/milestone.jpg" alt="milestone" width="160" height="50" class="alignleft" /></a>
<p>You&#8217;ll find full source code available for download as well as the demo files and step by step milestones all throughout the tutorial.</p>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F&amp;title=Tutorial%20to%20Create%20a%20Responsive%20Image%20Scroller%20in%20ActionScript%203.0&amp;notes=%0D%0AI%27ve%20written%20a%20tutorial%20which%20is%20published%20over%20at%20flash.tutsplus.%20This%20tutorial%20demonstrates%20how%20to%20create%20a%20horizontally%20scrolling%20image%20viewer%20and%20covers%20xml%20parsing%2C%20loading%20and%20resizing%20external%20images%2C%20and%20creating%20intuitive%20and%20responsive%20sc" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F&amp;title=Tutorial%20to%20Create%20a%20Responsive%20Image%20Scroller%20in%20ActionScript%203.0&amp;bodytext=%0D%0AI%27ve%20written%20a%20tutorial%20which%20is%20published%20over%20at%20flash.tutsplus.%20This%20tutorial%20demonstrates%20how%20to%20create%20a%20horizontally%20scrolling%20image%20viewer%20and%20covers%20xml%20parsing%2C%20loading%20and%20resizing%20external%20images%2C%20and%20creating%20intuitive%20and%20responsive%20sc" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Tutorial%20to%20Create%20a%20Responsive%20Image%20Scroller%20in%20ActionScript%203.0&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F&amp;t=Tutorial%20to%20Create%20a%20Responsive%20Image%20Scroller%20in%20ActionScript%203.0" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F&amp;title=Tutorial%20to%20Create%20a%20Responsive%20Image%20Scroller%20in%20ActionScript%203.0&amp;annotation=%0D%0AI%27ve%20written%20a%20tutorial%20which%20is%20published%20over%20at%20flash.tutsplus.%20This%20tutorial%20demonstrates%20how%20to%20create%20a%20horizontally%20scrolling%20image%20viewer%20and%20covers%20xml%20parsing%2C%20loading%20and%20resizing%20external%20images%2C%20and%20creating%20intuitive%20and%20responsive%20sc" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F&amp;title=Tutorial%20to%20Create%20a%20Responsive%20Image%20Scroller%20in%20ActionScript%203.0&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=%0D%0AI%27ve%20written%20a%20tutorial%20which%20is%20published%20over%20at%20flash.tutsplus.%20This%20tutorial%20demonstrates%20how%20to%20create%20a%20horizontally%20scrolling%20image%20viewer%20and%20covers%20xml%20parsing%2C%20loading%20and%20resizing%20external%20images%2C%20and%20creating%20intuitive%20and%20responsive%20sc" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F&amp;title=Tutorial%20to%20Create%20a%20Responsive%20Image%20Scroller%20in%20ActionScript%203.0" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F&amp;title=Tutorial%20to%20Create%20a%20Responsive%20Image%20Scroller%20in%20ActionScript%203.0" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Tutorial%20to%20Create%20a%20Responsive%20Image%20Scroller%20in%20ActionScript%203.0%20-%20http%3A%2F%2Fblog.circlecube.com%2F2009%2F08%2Ftutorial%2Ftutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2009/08/tutorial/tutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Forthcoming Actionscript Image Scroller Tutorial</title>
		<link>http://blog.circlecube.com/2009/07/tutorial/forthcoming-actionscript-image-scroller-tutorial/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=forthcoming-actionscript-image-scroller-tutorial</link>
		<comments>http://blog.circlecube.com/2009/07/tutorial/forthcoming-actionscript-image-scroller-tutorial/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 22:30:49 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[portfolio]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=975</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2009/07/tutorial/forthcoming-actionscript-image-scroller-tutorial/"><img align="left" hspace="5" width="150" src="http://blog.circlecube.com/wp-content/uploads/2009/07/image-scroller-thumbnail1.jpg" class="alignleft wp-post-image tfe" alt="image-scroller-thumbnail" title="image-scroller-thumbnail" /></a>Here is a preview of a file I&#8217;m writing a tutorial for. It&#8217;s nothing groundbreaking, but it deals with many normal tasks and will show my process a bit. This tutorial will show how to create a horizontally scrolling image viewer. It will cover xml loading &#038; parsing, loading &#038; resizing external images to fit [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.circlecube.com/wp-content/uploads/2009/07/image-scroller-thumbnail1.jpg" alt="image-scroller-thumbnail" title="image-scroller-thumbnail" width="440" height="142" class="aligncenter size-full wp-image-980" /></p>
<p>Here is a preview of a file I&#8217;m writing a tutorial for. It&#8217;s nothing groundbreaking, but it deals with many normal tasks and will show my process a bit. This tutorial will show how to create a horizontally scrolling image viewer. It will cover xml loading &#038; parsing, loading &#038; resizing external images to fit into a scrollable container, and creating intuitive and responsive scrolling!</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_image-scroller-example_936824321"
			class="flashmovie"
			width="550"
			height="137">
	<param name="movie" value="http://blog.circlecube.com/wp-content/uploads/2009/07/image-scroller-example.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.circlecube.com/wp-content/uploads/2009/07/image-scroller-example.swf"
			name="fm_image-scroller-example_936824321"
			width="550"
			height="137">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Let me know what you think, and if there&#8217;s anything you want specifically mentioned/explained in it I&#8217;ll do my best! Or if you have any ideas of how this could be improved.</p>
<blockquote><p>Update: The article/tutorial has now been published follow the link to the<a href="http://blog.circlecube.com/2009/08/tutorial/tutorial-to-create-a-responsive-image-scroller-in-actionscript-3-0/">Tutorial to Create a Responsive Image Scroller in ActionScript 3.0</a></p></blockquote>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F&amp;title=Forthcoming%20Actionscript%20Image%20Scroller%20Tutorial&amp;notes=%0D%0AHere%20is%20a%20preview%20of%20a%20file%20I%27m%20writing%20a%20tutorial%20for.%20It%27s%20nothing%20groundbreaking%2C%20but%20it%20deals%20with%20many%20normal%20tasks%20and%20will%20show%20my%20process%20a%20bit.%20This%20tutorial%20will%20show%20how%20to%20create%20a%20horizontally%20scrolling%20image%20viewer.%20It%20will%20cover%20xml%20" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F&amp;title=Forthcoming%20Actionscript%20Image%20Scroller%20Tutorial&amp;bodytext=%0D%0AHere%20is%20a%20preview%20of%20a%20file%20I%27m%20writing%20a%20tutorial%20for.%20It%27s%20nothing%20groundbreaking%2C%20but%20it%20deals%20with%20many%20normal%20tasks%20and%20will%20show%20my%20process%20a%20bit.%20This%20tutorial%20will%20show%20how%20to%20create%20a%20horizontally%20scrolling%20image%20viewer.%20It%20will%20cover%20xml%20" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Forthcoming%20Actionscript%20Image%20Scroller%20Tutorial&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F&amp;t=Forthcoming%20Actionscript%20Image%20Scroller%20Tutorial" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F&amp;title=Forthcoming%20Actionscript%20Image%20Scroller%20Tutorial&amp;annotation=%0D%0AHere%20is%20a%20preview%20of%20a%20file%20I%27m%20writing%20a%20tutorial%20for.%20It%27s%20nothing%20groundbreaking%2C%20but%20it%20deals%20with%20many%20normal%20tasks%20and%20will%20show%20my%20process%20a%20bit.%20This%20tutorial%20will%20show%20how%20to%20create%20a%20horizontally%20scrolling%20image%20viewer.%20It%20will%20cover%20xml%20" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F&amp;title=Forthcoming%20Actionscript%20Image%20Scroller%20Tutorial&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=%0D%0AHere%20is%20a%20preview%20of%20a%20file%20I%27m%20writing%20a%20tutorial%20for.%20It%27s%20nothing%20groundbreaking%2C%20but%20it%20deals%20with%20many%20normal%20tasks%20and%20will%20show%20my%20process%20a%20bit.%20This%20tutorial%20will%20show%20how%20to%20create%20a%20horizontally%20scrolling%20image%20viewer.%20It%20will%20cover%20xml%20" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F&amp;title=Forthcoming%20Actionscript%20Image%20Scroller%20Tutorial" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F&amp;title=Forthcoming%20Actionscript%20Image%20Scroller%20Tutorial" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Forthcoming%20Actionscript%20Image%20Scroller%20Tutorial%20-%20http%3A%2F%2Fblog.circlecube.com%2F2009%2F07%2Ftutorial%2Fforthcoming-actionscript-image-scroller-tutorial%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2009/07/tutorial/forthcoming-actionscript-image-scroller-tutorial/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Actionscript Drag &amp; Drop Tutorial &#124; Vertical and Horizontal Flash Sliders</title>
		<link>http://blog.circlecube.com/2009/05/tutorial/actionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=actionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders</link>
		<comments>http://blog.circlecube.com/2009/05/tutorial/actionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders/#comments</comments>
		<pubDate>Tue, 19 May 2009 01:52:56 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=858</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2009/05/tutorial/actionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders/"><img align="left" hspace="5" width="150" src="http://blog.circlecube.com/wp-content/uploads/2009/05/as3dragdrop-slider.png" class="alignleft wp-post-image tfe" alt="as3dragdrop-slider png" title="as3dragdrop-slider png" /></a>A specific use of drag and drop which is a bit more complicated than your average drag &#038; drop needs is a slider. You can use components, but I usually prefer using my own graphics and code, partly because the components tend to bloat the filesize of the swf and partly because that&#8217;s just how [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.circlecube.com/wp-content/uploads/2009/05/as3dragdrop-slider.png" alt="as3dragdrop-slider png" title="as3dragdrop-slider png" width="150" height="150" class="alignleft size-full wp-image-864" /> A specific use of drag and drop which is a bit more complicated than your average <a href="http://blog.circlecube.com/2009/04/tutorial/flash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3/">drag &#038; drop</a> needs is a slider. You can use components, but I usually prefer using my own graphics and code, partly because the components tend to bloat the filesize of the swf and partly because that&#8217;s just how I am, I like to make it myself. Many projects I&#8217;ve worked on require sliders as a form of user input, such as a volume control in my <a href="http://bit.ly/P0UZM" target="_blank">video player</a>, or the inputs for my <a href="http://blog.circlecube.com/2008/10/portfolio/voters-aide-prioritize-the-issues-this-election-interactive-flash-app/">Voter&#8217;s Aide app</a> that let users assign value to issues in the 2008 presidential election. I figured I&#8217;d just pull out the code I used with the sliders there, since it was already done. The issue with sliders is we need to restrict the dragging to a certain area, which in itself is a line of code, but I also prefer to allow users to click the actual bar as well for quick selection.</p>
<h2>Example</h2>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_as3dragdrop-sliders_1069548151"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://blog.circlecube.com/wp-content/uploads/2009/05/as3dragdrop-sliders.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.circlecube.com/wp-content/uploads/2009/05/as3dragdrop-sliders.swf"
			name="fm_as3dragdrop-sliders_1069548151"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<h2>Vertical Slider Steps</h2>
<p>The vertical slider here goes from 0 &#8211; 100. We need to drag the handle but have it restricted to the slider, so users won&#8217;t be confused when they click and drag the handle off the slider and break it. We want to click the background bar of the slider and have the handle snap to that place, and we need to be able to see what value the slider holds (0 &#8211; 100). I made this code to be pretty reusable, as long as the slider is set up in similar fashion.</p>
<ol>
<li>Make graphics for slider bg and handle</li>
<li>Put the graphics into a slider mc</li>
<li>Place them each at 0,0 and center their registration points (for easier control and code later)</li>
<li>Assign button mode to handle and bar (for better usability)</li>
<li>Add Mouse Down Event Listener for handle and bar and assign press function</li>
<li>In bar press function set position of handle according to mouse position, and then call the handle press function</li>
<li>In handle press function remove the Mouse Down listeners and add stage mouse event listeners for both mouse Up and Move (Stage listeners emulate onReleaseOutside (from as2) and also provide more accurate results)</li>
<li>Define dragging area as a rectangle(x, y, width, height), if you&#8217;ve do the set up earlier it should be close to Rectangle(0,0,0,slider.bar.height);</li>
<li>Begin dragging handle and apply the drag area limiting rectangle</li>
<li>Mouse Move function find value (should simply be the handle&#8217;s y position) and updateAfterEvent for smooth animation</li>
<li>Mouse Release function remove stage listeners, re-add the listeners to the slider and stop dragging</li>
</ol>
<h2>Actionscript (as3)</h2>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// Vertical Slider</span><br />
sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
sliderVertical<span style="color: #000066; font-weight: bold;">.</span>bar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> verticalHandlePress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
sliderVertical<span style="color: #000066; font-weight: bold;">.</span>bar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> verticalBarPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> verticalBarPress<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = sliderVertical<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseY</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; verticalHandlePress<span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #339966; font-weight: bold;">function</span> verticalHandlePress<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> verticalHandlePress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderVertical<span style="color: #000066; font-weight: bold;">.</span>bar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> verticalBarPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_UP</span><span style="color: #000066; font-weight: bold;">,</span> verticalHandleRelease<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_MOVE</span><span style="color: #000066; font-weight: bold;">,</span> verticalHandleDrag<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//limit dragging area</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> verticalDragArea<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000066; font-weight: bold;">-</span>sliderVertical<span style="color: #000066; font-weight: bold;">.</span>bar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">startDrag</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> verticalDragArea<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #339966; font-weight: bold;">function</span> verticalHandleRelease<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_UP</span><span style="color: #000066; font-weight: bold;">,</span> verticalHandleRelease<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_MOVE</span><span style="color: #000066; font-weight: bold;">,</span> verticalHandleDrag<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderVertical<span style="color: #000066; font-weight: bold;">.</span>bar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> verticalBarPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> verticalHandlePress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stopDrag</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; updateVNumber<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #339966; font-weight: bold;">function</span> verticalHandleDrag<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">updateAfterEvent</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; updateVNumber<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #339966; font-weight: bold;">function</span> updateVNumber<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; sliderVertical<span style="color: #000066; font-weight: bold;">.</span>sliderValue = sliderVertical<span style="color: #000066; font-weight: bold;">.</span>stat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">htmlText</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">abs</span><span style="color: #000000;">&#40;</span>sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderVertical<span style="color: #000066; font-weight: bold;">.</span>stat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> sliderVertical<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<h2>Horizontal Slider Steps</h2>
<p>Pretty much the same as the vertical slider, but adjust heights and y positions to widths and x positions. Note in this example I have a range of (-100 to 100) and to accomplish the bar I just reused the same on flipping it around, so here we have the handle, the barLeft and the barRight. I use both of these combined to calculate the limiting rectangle area.</p>
<h2>Actionscript (as3)</h2>
<div class="codecolorer-container actionscript3 mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">// Horizontal Slider</span><br />
sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barLeft<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barRight<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> horizontalHandlePress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barLeft<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> horizontalBarPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barRight<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> horizontalBarPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> horizontalBarPress<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; horizontalHandlePress<span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #339966; font-weight: bold;">function</span> horizontalHandlePress<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> horizontalHandlePress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barLeft<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> horizontalBarPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barRight<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> horizontalBarPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_UP</span><span style="color: #000066; font-weight: bold;">,</span> horizontalHandleRelease<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_MOVE</span><span style="color: #000066; font-weight: bold;">,</span> horizontalHandleDrag<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//limit dragging area</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> dragArea<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">-</span>sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barLeft<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barLeft<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">+</span>sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barRight<span style="color: #000066; font-weight: bold;">.</span>width<span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">startDrag</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> dragArea<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #339966; font-weight: bold;">function</span> horizontalHandleRelease<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_UP</span><span style="color: #000066; font-weight: bold;">,</span> horizontalHandleRelease<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_MOVE</span><span style="color: #000066; font-weight: bold;">,</span> horizontalHandleDrag<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> horizontalHandlePress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barLeft<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> horizontalBarPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>barRight<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> horizontalBarPress<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stopDrag</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; updateHNumber<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #339966; font-weight: bold;">function</span> horizontalHandleDrag<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">updateAfterEvent</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; updateHNumber<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #339966; font-weight: bold;">function</span> updateHNumber<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>sliderValue = sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>stat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">htmlText</span> = sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>stat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">-</span> sliderHorizontal<span style="color: #000066; font-weight: bold;">.</span>handle<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<h2>Source</h2>
<p>source <a class="download-box" href="http://blog.circlecube.com/wp-content/uploads/2009/05/as3dragdrop-sliders.fla">as3dragdrop-sliders.fla</a> file</p>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F&amp;title=Actionscript%20Drag%20%26%20Drop%20Tutorial%20%7C%20Vertical%20and%20Horizontal%20Flash%20Sliders&amp;notes=%20A%20specific%20use%20of%20drag%20and%20drop%20which%20is%20a%20bit%20more%20complicated%20than%20your%20average%20drag%20%26%20drop%20needs%20is%20a%20slider.%20You%20can%20use%20components%2C%20but%20I%20usually%20prefer%20using%20my%20own%20graphics%20and%20code%2C%20partly%20because%20the%20components%20tend%20to%20bloat%20the%20filesize%20of" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F&amp;title=Actionscript%20Drag%20%26%20Drop%20Tutorial%20%7C%20Vertical%20and%20Horizontal%20Flash%20Sliders&amp;bodytext=%20A%20specific%20use%20of%20drag%20and%20drop%20which%20is%20a%20bit%20more%20complicated%20than%20your%20average%20drag%20%26%20drop%20needs%20is%20a%20slider.%20You%20can%20use%20components%2C%20but%20I%20usually%20prefer%20using%20my%20own%20graphics%20and%20code%2C%20partly%20because%20the%20components%20tend%20to%20bloat%20the%20filesize%20of" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Actionscript%20Drag%20%26%20Drop%20Tutorial%20%7C%20Vertical%20and%20Horizontal%20Flash%20Sliders&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F&amp;t=Actionscript%20Drag%20%26%20Drop%20Tutorial%20%7C%20Vertical%20and%20Horizontal%20Flash%20Sliders" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F&amp;title=Actionscript%20Drag%20%26%20Drop%20Tutorial%20%7C%20Vertical%20and%20Horizontal%20Flash%20Sliders&amp;annotation=%20A%20specific%20use%20of%20drag%20and%20drop%20which%20is%20a%20bit%20more%20complicated%20than%20your%20average%20drag%20%26%20drop%20needs%20is%20a%20slider.%20You%20can%20use%20components%2C%20but%20I%20usually%20prefer%20using%20my%20own%20graphics%20and%20code%2C%20partly%20because%20the%20components%20tend%20to%20bloat%20the%20filesize%20of" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F&amp;title=Actionscript%20Drag%20%26%20Drop%20Tutorial%20%7C%20Vertical%20and%20Horizontal%20Flash%20Sliders&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=%20A%20specific%20use%20of%20drag%20and%20drop%20which%20is%20a%20bit%20more%20complicated%20than%20your%20average%20drag%20%26%20drop%20needs%20is%20a%20slider.%20You%20can%20use%20components%2C%20but%20I%20usually%20prefer%20using%20my%20own%20graphics%20and%20code%2C%20partly%20because%20the%20components%20tend%20to%20bloat%20the%20filesize%20of" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F&amp;title=Actionscript%20Drag%20%26%20Drop%20Tutorial%20%7C%20Vertical%20and%20Horizontal%20Flash%20Sliders" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F&amp;title=Actionscript%20Drag%20%26%20Drop%20Tutorial%20%7C%20Vertical%20and%20Horizontal%20Flash%20Sliders" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Actionscript%20Drag%20%26%20Drop%20Tutorial%20%7C%20Vertical%20and%20Horizontal%20Flash%20Sliders%20-%20http%3A%2F%2Fblog.circlecube.com%2F2009%2F05%2Ftutorial%2Factionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2009/05/tutorial/actionscript-drag-drop-tutorial-vertical-and-horizontal-flash-sliders/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash Drag and Drop Tutorial &#124; startDrag Actionscript</title>
		<link>http://blog.circlecube.com/2009/04/tutorial/flash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=flash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3</link>
		<comments>http://blog.circlecube.com/2009/04/tutorial/flash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 04:28:49 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=379</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2009/04/tutorial/flash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3/"><img align="left" hspace="5" width="150" height="150" src="http://blog.circlecube.com/wp-content/uploads/2009/04/drag-drap-as3-ball-150x150.png" class="alignleft wp-post-image tfe" alt="drag-drap-as3-ball" title="drag-drap-as3-ball" /></a>I find that Drag and Drop is the most intuitive form of user interaction (at least using a mouse). Actionscript has some of this functionality built in, with the interactive functions startDrag and stopDrag, these can help make our coding pretty easy. If you are transitioning from as2, the code was incredibly simple: Actionscript2 123456on [...]]]></description>
			<content:encoded><![CDATA[<p>I find that Drag and Drop is the most intuitive form of user interaction (at least using a mouse). Actionscript has some of this functionality built in, with the interactive functions startDrag and stopDrag, these can help make our coding pretty easy. If you are transitioning from as2, the code was incredibly simple:</p>
<h2>Actionscript2</h2>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">on</span> <span style="color: #66cc66;">&#40;</span>press<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">startDrag</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #0066CC;">on</span> <span style="color: #66cc66;">&#40;</span>release, releaseOutside<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">stopDrag</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>On the movie clip action panel you&#8217;d just put that script, which is actually pretty readable even if you don&#8217;t know code. The releaseOutside is to keep from the clip missing the release event, because sometimes if a user released the mouse button but was not currently over the clip being dragged for whatever reason, it will not stop dragging.</p>
<h2>Actionscript 3</h2>
<p><img src="http://blog.circlecube.com/wp-content/uploads/2009/04/drag-drap-as3-ball.png" alt="drag-drap-as3-ball" title="drag-drap-as3-ball" width="100" height="100" class="alignleft size-full wp-image-827" />Some things have changed with as3, other than the actual coding structure, the biggest change for me doing drag and drop in the new actionscript was that the mouse events have changed. There is no more a press or release. They were replaced with, MOUSE_DOWN and MOUSE_UP. There is no more releaseOutside either and this one is a little more complicated to find among the new MouseEvent list.<br />
Leaving it out works, but we still have the same problem. Check out the working example below and try dragging the red ball to the green or yellow one and drop it there. Since the green is above the red in the layer sequence, the mouse is over the green and when the MouseEvent.MOUSE_UP fires, it&#8217;s not on the red ball but on the green, so we don&#8217;t get to the code that drops the red ball. So the red ball code basically has times when the dragging sticks even after we release the mouse button. Not to mention the dragging is very jumpy!</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ballRed.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, dragRed<span style="color: #66cc66;">&#41;</span>;<br />
ballRed.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropRed<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">function</span> dragRed<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; ballRed.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> dropRed<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; ballRed.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Using the Mouse Move event will help us to customize our behavior a bit more. Plus I wanted to get a more abstract level to it, so I could apply the event listeners to any display object and use the event properties to target the right clips. We begin the drag with the Mouse Down, and the create some other eventListeners for the stage that will watch the Mouse Move and Up events. So clicking on the green or yellow ball, fires the grabMe function which sets the me variable (which will hold any object) to the current target of the event, which should always be the object that you click. So we are using the same code for both the green and yellow ball. I&#8217;m a big fan of code consolidation and reuse, it takes a little more effort, but the code is much more clean and portable even. Then we add the event listeners for the stage on MOUSE_MOVE and MOUSE_UP. So first, mthe dragMe function, just says to update after event. This makes the animation smoother cause it only updates the display after the event completes it&#8217;s process. Then the drop me function is attached to the stage, so anywhere you release the mouse, the object will stop dragging, plus we remove the stage event listeners and add back the listener for the original object (me). Note the buttonMode property as well, this will make the cursor turn to a hand when you hover that object.</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ballYellow.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, grabMe<span style="color: #66cc66;">&#41;</span>;<br />
ballYellow.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
ballGreen.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, grabMe<span style="color: #66cc66;">&#41;</span>;<br />
ballGreen.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> me:<span style="color: #0066CC;">Object</span>;<br />
<span style="color: #000000; font-weight: bold;">function</span> grabMe<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; me = <span style="color: #0066CC;">e</span>.<span style="color: #006600;">currentTarget</span>;<br />
&nbsp; &nbsp; me.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, grabMe<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; me.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, dragMe<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropMe<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> dropMe<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, dropMe<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, dragMe<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; me.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; me.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, grabMe<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> dragMe<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">updateAfterEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>This functionality is much smoother and then when I want to add more code to the dragging or dropping, I have a place to do it already!</p>
<h2>Example</h2>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_as3dragdrop-ball_1665967917"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://blog.circlecube.com/wp-content/uploads/2009/04/as3dragdrop-ball.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.circlecube.com/wp-content/uploads/2009/04/as3dragdrop-ball.swf"
			name="fm_as3dragdrop-ball_1665967917"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<h2>Source</h2>
<p><a class="download-box" href="http://blog.circlecube.com/wp-content/uploads/2009/04/as3dragdrop-ball.fla" target="_blank" >as3dragdrop-ball.fla</a></p>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F&amp;title=Flash%20Drag%20and%20Drop%20Tutorial%20%7C%20startDrag%20Actionscript&amp;notes=I%20find%20that%20Drag%20and%20Drop%20is%20the%20most%20intuitive%20form%20of%20user%20interaction%20%28at%20least%20using%20a%20mouse%29.%20Actionscript%20has%20some%20of%20this%20functionality%20built%20in%2C%20with%20the%20interactive%20functions%20startDrag%20and%20stopDrag%2C%20these%20can%20help%20make%20our%20coding%20pretty%20easy" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F&amp;title=Flash%20Drag%20and%20Drop%20Tutorial%20%7C%20startDrag%20Actionscript&amp;bodytext=I%20find%20that%20Drag%20and%20Drop%20is%20the%20most%20intuitive%20form%20of%20user%20interaction%20%28at%20least%20using%20a%20mouse%29.%20Actionscript%20has%20some%20of%20this%20functionality%20built%20in%2C%20with%20the%20interactive%20functions%20startDrag%20and%20stopDrag%2C%20these%20can%20help%20make%20our%20coding%20pretty%20easy" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Flash%20Drag%20and%20Drop%20Tutorial%20%7C%20startDrag%20Actionscript&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F&amp;t=Flash%20Drag%20and%20Drop%20Tutorial%20%7C%20startDrag%20Actionscript" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F&amp;title=Flash%20Drag%20and%20Drop%20Tutorial%20%7C%20startDrag%20Actionscript&amp;annotation=I%20find%20that%20Drag%20and%20Drop%20is%20the%20most%20intuitive%20form%20of%20user%20interaction%20%28at%20least%20using%20a%20mouse%29.%20Actionscript%20has%20some%20of%20this%20functionality%20built%20in%2C%20with%20the%20interactive%20functions%20startDrag%20and%20stopDrag%2C%20these%20can%20help%20make%20our%20coding%20pretty%20easy" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F&amp;title=Flash%20Drag%20and%20Drop%20Tutorial%20%7C%20startDrag%20Actionscript&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=I%20find%20that%20Drag%20and%20Drop%20is%20the%20most%20intuitive%20form%20of%20user%20interaction%20%28at%20least%20using%20a%20mouse%29.%20Actionscript%20has%20some%20of%20this%20functionality%20built%20in%2C%20with%20the%20interactive%20functions%20startDrag%20and%20stopDrag%2C%20these%20can%20help%20make%20our%20coding%20pretty%20easy" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F&amp;title=Flash%20Drag%20and%20Drop%20Tutorial%20%7C%20startDrag%20Actionscript" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F&amp;title=Flash%20Drag%20and%20Drop%20Tutorial%20%7C%20startDrag%20Actionscript" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Flash%20Drag%20and%20Drop%20Tutorial%20%7C%20startDrag%20Actionscript%20-%20http%3A%2F%2Fblog.circlecube.com%2F2009%2F04%2Ftutorial%2Fflash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2009/04/tutorial/flash-drag-and-drop-tutorial-basic-startdrag-to-flexible-mouse-event-listeners-actionscript-2-as3/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to use fullscreen in AS3 &#124; Stage Display State Tutorial</title>
		<link>http://blog.circlecube.com/2009/03/tutorial/how-to-use-fullscreen-in-as3-stage-display-state-tutorial/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=how-to-use-fullscreen-in-as3-stage-display-state-tutorial</link>
		<comments>http://blog.circlecube.com/2009/03/tutorial/how-to-use-fullscreen-in-as3-stage-display-state-tutorial/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 13:19:38 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=803</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2009/03/tutorial/how-to-use-fullscreen-in-as3-stage-display-state-tutorial/"><img align="left" hspace="5" width="150" src="http://blog.circlecube.com/wp-content/uploads/2009/03/fullscreen_tut-150x150.png" class="alignleft wp-post-image tfe" alt="fullscreen_tut png" title="fullscreen_tut png" /></a>One of the best features of the flash player if you&#8217;re doing video is the fullscreen functionality. It has been a question I&#8217;ve heard repeatedly. There are limits to what you can do in fullscreen. Such as minimal keyboard support while in fullscreen. But it is perfect for a video player! Who doesn&#8217;t want to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.circlecube.com/wp-content/uploads/2009/03/fullscreen_tut-150x150.png" alt="fullscreen_tut png" title="fullscreen_tut png" width="150" height="150" class="alignleft size-thumbnail wp-image-814" /><br />
One of the best features of the flash player if you&#8217;re doing video is the fullscreen functionality. It has been a question I&#8217;ve heard repeatedly. There are limits to what you can do in fullscreen. Such as minimal keyboard support while in fullscreen. But it is perfect for a video player! Who doesn&#8217;t want to see a video expanded to full screen mode?</p>
<p>There are a couple things to consider when coding fullscreen into your flash. Remember the hard coded &#8220;Press Esc to exit full screen mode.&#8221; that Adobe has placed into the flash player. This is untouchable by developers, and the function returns to normal stage display state. So we call the function to go fullscreen, but the exit fullscreen has already been written for us. This can pose a problem though, when we need the player to do something when we exit fullscreen, that is when we want it to do something more than the generic black box function adobe includes.</p>
<h2>Steps</h2>
<ol>
<li>specify stage properties</li>
<li>full screen button and listeners</li>
<li>stage fullscreenEvent listener</li>
<li>(functions for each)</li>
<li>allowfullscreen = true</li>
</ol>
<h2>Example</h2>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_fullscreen_tut_1631987226"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://blog.circlecube.com/wp-content/uploads/2009/03/fullscreen_tut.swf" />
	<param name="allowfullscreen" value="true" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.circlecube.com/wp-content/uploads/2009/03/fullscreen_tut.swf"
			name="fm_fullscreen_tut_1631987226"
			width="550"
			height="400">
		<param name="allowfullscreen" value="true" />
	<!--<![endif]-->
		<a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>1. Stage properties exist that allow us to specify what type of fullscreen we want.  We can have the swf scale to fit the fullscreen area (StageScaleMode.SHOW_ALL), not scale at all (StageScaleMode.NO_SCALE), skew to fit fullscreen (StageScaleMode.EXACT_FIT), and scale to fill fullscreen area (Stage.ScaleMode.NO_BORDER).  We may also edit the alignment of the stage in the fullscreen area; in this example I&#8217;m using TOP, but refer to <a title="public final class StageAlign" href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/StageAlign.html" target="_blank">documentation </a>for more options</p>
<p>2. Adobe has placed restrictions on when a swf can enter fullscreen, and has deemed that it must result from a user interaction, a mouse click or keystroke. So create your buttons (or keyListeners). I prefer to have one button to enter fullscreen and another to exit, and have them both call the same function to toggle fullscreen. It gives a clearer communication to the user. I then control the visibility of these buttons depending on the current display state of the stage.</p>
<p>3. Another listener to watch the stage dispaly state.  stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreenChange); This will fire every time the stage display state changes. We need this because as I mentioned earlier, when entering fullscreen we use our own function, but the &#8216;hit esc to exit fullscreen&#8217; functionality is built into the flash player, we can&#8217;t update our stage layout or button visibility without watching to catch when the display state is changed. Using this method we can update our stage layout any and every time.</p>
<p>4. Of course flesh out the fullscreenToggle function to include anything else you need.</p>
<p>5. Lastly, for a SWF file embedded in an HTML page, the HTML code to embed Flash Player  must include a &#8216;param&#8217; tag and  &#8216;embed&#8217; attribute with the name  &#8216;allowFullScreen&#8217; and value &#8216;true&#8217;, like this:</p>
<pre>&lt;object&gt;
    ...
    &lt;param name="allowFullScreen" value="true" /&gt;
    &lt;embed ... allowfullscreen="true" /&gt;
&lt;/object&gt;</pre>
<p>The allowFullScreen tag enables full-screen mode in the player. If you do everything else right and don&#8217;t include this in your embed codes, fullscreen will not work. The default value is false if this attribute is omitted. Note the viewer must at least have Flash Player version 9,0,28,0 installed to use full-screen mode. Also note that  the simple (ctrl + enter) testing your movie in flash will not allow fullscreen either, you must use the debug tester (ctrl + shift + enter) &#8230; or go open the published swf in flash player.</p>
<h2>Actionscript</h2>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = StageScaleMode.<span style="color: #006600;">SHOW_ALL</span>;<br />
<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = StageAlign.<span style="color: #006600;">TOP</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> stageDisplayAdjustCounter:uint = <span style="color: #cc66cc;">0</span>;<br />
<br />
fsb.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, fullscreenToggle<span style="color: #66cc66;">&#41;</span>;<br />
ssb.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, fullscreenToggle<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FullScreenEvent.<span style="color: #006600;">FULL_SCREEN</span>, onFullscreenChange<span style="color: #66cc66;">&#41;</span>;<br />
<br />
fsb.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
ssb.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//fullscreen buttons need this to adjust the stage display state.</span><br />
<span style="color: #808080; font-style: italic;">//pressing escape to exit fullscreen bypasses this function</span><br />
<span style="color: #000000; font-weight: bold;">function</span> fullscreenToggle<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #0066CC;">status</span>.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span>stageDisplayAdjustCounter+<span style="color: #ff0000;">&quot;. fullscreenToggle from &quot;</span>+<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #808080; font-style: italic;">//normal mode, enter fullscreen mode</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> == StageDisplayState.<span style="color: #006600;">NORMAL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//set stage display state</span><br />
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> = StageDisplayState.<span style="color: #006600;">FULL_SCREEN</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//fullscreen mode, enter normal mode</span><br />
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> == StageDisplayState.<span style="color: #006600;">FULL_SCREEN</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//set stage display state</span><br />
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> = StageDisplayState.<span style="color: #006600;">NORMAL</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//here we subtract 1 from the counter because it has already incremented (in onFullscreenChange) when we set the display state above</span><br />
<br />
<span style="color: #0066CC;">status</span>.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>stageDisplayAdjustCounter-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>+<span style="color: #ff0000;">&quot;. fullscreenToggle to &quot;</span>+<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">status</span>.<span style="color: #006600;">scrollV</span> = <span style="color: #0066CC;">status</span>.<span style="color: #006600;">maxScrollV</span>;<br />
<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">//this function is called every and anytime the stage display state is adjusted</span><br />
<span style="color: #808080; font-style: italic;">//either by pressing our buttons or</span><br />
<span style="color: #000000; font-weight: bold;">function</span> onFullscreenChange<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:FullScreenEvent = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #0066CC;">status</span>.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span>stageDisplayAdjustCounter+<span style="color: #ff0000;">&quot;. onFullscreenChange<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">status</span>.<span style="color: #006600;">scrollV</span> = <span style="color: #0066CC;">status</span>.<span style="color: #006600;">maxScrollV</span>;<br />
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> == StageDisplayState.<span style="color: #006600;">FULL_SCREEN</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
fsb.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
ssb.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />
fsb.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
ssb.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
stageDisplayAdjustCounter++;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
onFullscreenChange<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div></td></tr></tbody></table></div>
<h2>Source</h2>
<p>Download <a class="download-box" href="http://blog.circlecube.com/wp-content/uploads/2009/03/fullscreen_tut.fla">fullscreen_tut.fla</a> file</p>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F&amp;title=How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial&amp;notes=%0D%0AOne%20of%20the%20best%20features%20of%20the%20flash%20player%20if%20you%27re%20doing%20video%20is%20the%20fullscreen%20functionality.%20It%20has%20been%20a%20question%20I%27ve%20heard%20repeatedly.%20There%20are%20limits%20to%20what%20you%20can%20do%20in%20fullscreen.%20Such%20as%20minimal%20keyboard%20support%20while%20in%20fullscree" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F&amp;title=How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial&amp;bodytext=%0D%0AOne%20of%20the%20best%20features%20of%20the%20flash%20player%20if%20you%27re%20doing%20video%20is%20the%20fullscreen%20functionality.%20It%20has%20been%20a%20question%20I%27ve%20heard%20repeatedly.%20There%20are%20limits%20to%20what%20you%20can%20do%20in%20fullscreen.%20Such%20as%20minimal%20keyboard%20support%20while%20in%20fullscree" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F&amp;t=How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F&amp;title=How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial&amp;annotation=%0D%0AOne%20of%20the%20best%20features%20of%20the%20flash%20player%20if%20you%27re%20doing%20video%20is%20the%20fullscreen%20functionality.%20It%20has%20been%20a%20question%20I%27ve%20heard%20repeatedly.%20There%20are%20limits%20to%20what%20you%20can%20do%20in%20fullscreen.%20Such%20as%20minimal%20keyboard%20support%20while%20in%20fullscree" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F&amp;title=How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=%0D%0AOne%20of%20the%20best%20features%20of%20the%20flash%20player%20if%20you%27re%20doing%20video%20is%20the%20fullscreen%20functionality.%20It%20has%20been%20a%20question%20I%27ve%20heard%20repeatedly.%20There%20are%20limits%20to%20what%20you%20can%20do%20in%20fullscreen.%20Such%20as%20minimal%20keyboard%20support%20while%20in%20fullscree" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F&amp;title=How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F&amp;title=How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial%20-%20http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fhow-to-use-fullscreen-in-as3-stage-display-state-tutorial%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2009/03/tutorial/how-to-use-fullscreen-in-as3-stage-display-state-tutorial/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Fullscreen in AS3 Tutorial &#124; Plus Firefox Flash bug when enter fullscreen keyboard events fired</title>
		<link>http://blog.circlecube.com/2009/03/tutorial/as3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=as3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events</link>
		<comments>http://blog.circlecube.com/2009/03/tutorial/as3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 20:59:54 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=789</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2009/03/tutorial/as3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events/"><img align="left" hspace="5" width="150" height="150" src="http://blog.circlecube.com/wp-content/uploads/2009/03/fs_keyboars_bug_thumbnail-150x150.png" class="alignleft wp-post-image tfe" alt="fullscreen_keyboard_bug_thumbnail" title="fullscreen_keyboard_bug_thumbnail" /></a>To view the full fullscreen tutorial go here: How to use fullscreen in AS3 &#124; Stage Display State Tutorial Sucks when you seem to have a bug in your code somewhere so you dissect your code over and over and are convinced that according to your code, everything should be fine, so you come back [...]]]></description>
			<content:encoded><![CDATA[<h3>To view the full fullscreen tutorial go here: <a href="http://blog.circlecube.com/2009/03/tutorial/how-to-use-fullscreen-in-as3-stage-display-state-tutorial/" >How to use fullscreen in AS3 | Stage Display State Tutorial</a></h3>
<p><img src="http://blog.circlecube.com/wp-content/uploads/2009/03/fs_keyboars_bug_thumbnail.png" alt="fullscreen_keyboard_bug_thumbnail" title="fullscreen_keyboard_bug_thumbnail" width="292" height="292" class="alignleft size-full wp-image-798" /><br />
Sucks when you seem to have a bug in your code somewhere so you dissect your code over and over and are convinced that according to your code, everything should be fine, so you come back later thinking fresher eyes will see it, and still can&#8217;t find the cause, and then resort to debugging with various trace statements&#8230;</p>
<p>I&#8217;ve been developing a custom flash player in as3. Fullscreen and all those bells and whistles&#8230; I could test locally and eveything was beautiful&#8230; but then upload and test in the browser and when I would go into fullscreen mode, the video would pause. Pretty annoying bug! So I&#8217;d go through my code and examine anywhere a call to pause the video (there are only two): pressing the play/pause button and pressing the spacebar (keyboard shortcut). I couldn&#8217;t find any correalation. I was thinking adobe must be doing some crazy security things when going into fullscreen&#8230; but no, no other video player I&#8217;ve seen does this!<br />
After commenting out my keyboard events, the bug is fixed! But I still can&#8217;t use the spacebar to pause/play. I love this functionality for usability. Isn&#8217;t that pretty standard for video? space to pause, it&#8217;s like second nature to me.</p>
<p>Does entering fullscreen really trigger a keyboard event equivalent to pressing my spacebar!? Sure enough. how much sense does that make, but it gets better! I had a friend test this swf and it worked fine for him. No pause on fullscreen! Wha!? Using good ole IE7&#8230; So yes, it&#8217;s a browser specific actionscript bug, firefox even! That was one of the things I liked about flash initially, not too much to mess with as far as cross browser issues once you get the swf embedded in the html, or so I thought.</p>
<p>So after playing with booleans to try to control when the keyboard events will be working.</p>
<p>Has anyone experienced this or another issue that just left you baffled, even after you figured out the bug?!</p>
<p>Well, I&#8217;ve done the right thing, I&#8217;ve posted about it to hopefully help anyone else having this issue. I created a test case file to rule out anything else in my code and make sure I&#8217;m not crazy.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_fullscreen_keyboardevent_bug_1835434297"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://blog.circlecube.com/wp-content/uploads/2009/03/fullscreen_keyboardevent_bug.swf" />
	<param name="bgcolor" value="#336666" />
	<param name="allowfullscreen" value="true" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.circlecube.com/wp-content/uploads/2009/03/fullscreen_keyboardevent_bug.swf"
			name="fm_fullscreen_keyboardevent_bug_1835434297"
			width="550"
			height="400">
		<param name="bgcolor" value="#336666" />
		<param name="allowfullscreen" value="true" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = StageScaleMode.<span style="color: #006600;">NO_SCALE</span>;<br />
<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = StageAlign.<span style="color: #006600;">TOP_LEFT</span>;<br />
<br />
fsb.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, fullscreenToggle<span style="color: #66cc66;">&#41;</span>;<br />
ssb.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, fullscreenToggle<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FullScreenEvent.<span style="color: #006600;">FULL_SCREEN</span>, onFullscreenChange<span style="color: #66cc66;">&#41;</span>;<br />
fsb.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
ssb.<span style="color: #006600;">buttonMode</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
onFullscreenChange<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> fullscreenToggle<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//normal mode, enter fullscreen mode</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> == StageDisplayState.<span style="color: #006600;">NORMAL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//set stage display state</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> = StageDisplayState.<span style="color: #006600;">FULL_SCREEN</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//fullscreen mode, enter normal mode</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> == StageDisplayState.<span style="color: #006600;">FULL_SCREEN</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//set stage display state</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> = StageDisplayState.<span style="color: #006600;">NORMAL</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; onFullscreenChange<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> onFullscreenChange<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:FullScreenEvent = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span> == StageDisplayState.<span style="color: #006600;">FULL_SCREEN</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; tracer<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;full screen&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; fsb.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ssb.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; tracer<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;small screen&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; fsb.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; ssb.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; tracer<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;toggle to &quot;</span>+<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">displayState</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>,keyDownListener<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> keyDownListener<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:KeyboardEvent<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; tracer<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;keyboard: keyCode: &quot;</span>+ <span style="color: #0066CC;">e</span>.<span style="color: #006600;">keyCode</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">var</span> tracerwindow:<span style="color: #0066CC;">TextField</span>;<br />
<span style="color: #000000; font-weight: bold;">function</span> tracer<span style="color: #66cc66;">&#40;</span> ...<span style="color: #006600;">args</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>tracerwindow == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tracerwindow = <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>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tracerwindow.<span style="color: #0066CC;">width</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tracerwindow.<span style="color: #0066CC;">height</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tracerwindow.<span style="color: #0066CC;">multiline</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>tracerwindow<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:uint = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> args.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tracerwindow.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; tracerwindow.<span style="color: #006600;">appendText</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>other places that I&#8217;ve found this mentioned that helped me understand what was going on:</p>
<p>http://dreamweaverforum.info/actionscript-3/123202-keyboard-event-full-screen.html</p>
<p>http://bugs.adobe.com/jira/browse/FP-814</p>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F&amp;title=Fullscreen%20in%20AS3%20Tutorial%20%7C%20Plus%20Firefox%20Flash%20bug%20when%20enter%20fullscreen%20keyboard%20events%20fired&amp;notes=To%20view%20the%20full%20fullscreen%20tutorial%20go%20here%3A%20How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial%0D%0A%0D%0A%0D%0ASucks%20when%20you%20seem%20to%20have%20a%20bug%20in%20your%20code%20somewhere%20so%20you%20dissect%20your%20code%20over%20and%20over%20and%20are%20convinced%20that%20according%20to%20your%20co" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F&amp;title=Fullscreen%20in%20AS3%20Tutorial%20%7C%20Plus%20Firefox%20Flash%20bug%20when%20enter%20fullscreen%20keyboard%20events%20fired&amp;bodytext=To%20view%20the%20full%20fullscreen%20tutorial%20go%20here%3A%20How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial%0D%0A%0D%0A%0D%0ASucks%20when%20you%20seem%20to%20have%20a%20bug%20in%20your%20code%20somewhere%20so%20you%20dissect%20your%20code%20over%20and%20over%20and%20are%20convinced%20that%20according%20to%20your%20co" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Fullscreen%20in%20AS3%20Tutorial%20%7C%20Plus%20Firefox%20Flash%20bug%20when%20enter%20fullscreen%20keyboard%20events%20fired&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F&amp;t=Fullscreen%20in%20AS3%20Tutorial%20%7C%20Plus%20Firefox%20Flash%20bug%20when%20enter%20fullscreen%20keyboard%20events%20fired" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F&amp;title=Fullscreen%20in%20AS3%20Tutorial%20%7C%20Plus%20Firefox%20Flash%20bug%20when%20enter%20fullscreen%20keyboard%20events%20fired&amp;annotation=To%20view%20the%20full%20fullscreen%20tutorial%20go%20here%3A%20How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial%0D%0A%0D%0A%0D%0ASucks%20when%20you%20seem%20to%20have%20a%20bug%20in%20your%20code%20somewhere%20so%20you%20dissect%20your%20code%20over%20and%20over%20and%20are%20convinced%20that%20according%20to%20your%20co" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F&amp;title=Fullscreen%20in%20AS3%20Tutorial%20%7C%20Plus%20Firefox%20Flash%20bug%20when%20enter%20fullscreen%20keyboard%20events%20fired&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=To%20view%20the%20full%20fullscreen%20tutorial%20go%20here%3A%20How%20to%20use%20fullscreen%20in%20AS3%20%7C%20Stage%20Display%20State%20Tutorial%0D%0A%0D%0A%0D%0ASucks%20when%20you%20seem%20to%20have%20a%20bug%20in%20your%20code%20somewhere%20so%20you%20dissect%20your%20code%20over%20and%20over%20and%20are%20convinced%20that%20according%20to%20your%20co" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F&amp;title=Fullscreen%20in%20AS3%20Tutorial%20%7C%20Plus%20Firefox%20Flash%20bug%20when%20enter%20fullscreen%20keyboard%20events%20fired" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F&amp;title=Fullscreen%20in%20AS3%20Tutorial%20%7C%20Plus%20Firefox%20Flash%20bug%20when%20enter%20fullscreen%20keyboard%20events%20fired" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Fullscreen%20in%20AS3%20Tutorial%20%7C%20Plus%20Firefox%20Flash%20bug%20when%20enter%20fullscreen%20keyboard%20events%20fired%20-%20http%3A%2F%2Fblog.circlecube.com%2F2009%2F03%2Ftutorial%2Fas3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2009/03/tutorial/as3-firefox-bug-enter-fullscreen-broadcasts-keyboard-events/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Random Movement &#124; Brownian revisited for as3</title>
		<link>http://blog.circlecube.com/2009/02/tutorial/random-movement-brownian-revisited-for-as3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=random-movement-brownian-revisited-for-as3</link>
		<comments>http://blog.circlecube.com/2009/02/tutorial/random-movement-brownian-revisited-for-as3/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 18:51:49 +0000</pubDate>
		<dc:creator>Evan Mullins</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[abstract]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://blog.circlecube.com/?p=683</guid>
		<description><![CDATA[<a href="http://blog.circlecube.com/2009/02/tutorial/random-movement-brownian-revisited-for-as3/"><img align="left" hspace="5" width="150" height="150" src="http://blog.circlecube.com/wp-content/uploads/2009/02/as3brownian-thumb-150x150.png" class="alignleft wp-post-image tfe" alt="as3brownian thumb png" title="as3brownian thumb png" /></a>I have had feedback that certain random movements I program are a bit &#8220;jumpy&#8221;. Such as my old brownian movement tutorial and I really noticed it in my last tutorial, the parallax 3d depth effect tutorial. I&#8217;ve been thinking about it and looking around at some code and now have this updated brownian movement example! [...]]]></description>
			<content:encoded><![CDATA[<p>I have had feedback that certain random movements I program are a bit &#8220;jumpy&#8221;. Such as my old <a href="http://blog.circlecube.com/2008/06/tutorial/brownian-movement-in-actionscript-random-motion-tutorial/">brownian movement tutorial</a> and I really noticed it in my last tutorial, <a href="http://blog.circlecube.com/2009/01/tutorial/dynamic-3d-space-floating-sketches-tutorial/">the parallax 3d depth effect tutorial</a>.  I&#8217;ve been thinking about it and looking around at some code and now have this updated brownian movement example! Updated for as3 as well as making it less jumpy.</p>
<p><img src="http://blog.circlecube.com/wp-content/uploads/2009/02/as3brownian-thumb.png" alt="as3brownian thumb png" title="as3brownian thumb png" width="200" height="200" class="alignleft size-full wp-image-717" />First I&#8217;ll explain what I&#8217;ve found to be the reason of the jumpiness. And then explain and show what can be done to make this movement be more smooth.</p>
<p>So to examine the old jumpy code. Jump back to the first version post <a href="http://blog.circlecube.com/2008/06/tutorial/brownian-movement-in-actionscript-random-motion-tutorial/">here</a>. I think my technique was well thought out here, but the application was poor. It was recalculating the velocities every single frame and then incrementing the coordinate positions by the newly calculated velocities&#8230; This is where the jumpiness comes in. Even though the random value was named velocity, it didn&#8217;t actually affect the dot&#8217;s velocity, it was just a variable that stored the random value used to move the current x/y coordinates.<br />
To help the animation be more smooth, the velocity needs to be more smooth. The velocity, rather than calculating it fresh each frame, should be randomly <em>modified</em> each frame. And then the new velocity will calculate the new &#8216;random&#8217; position. Another addition is to introduce another force to dampen the velocity over time, so things don&#8217;t get too crazy&#8230;</p>
<h2>Steps:</h2>
<ol>
<li>Modify velocity randomly</li>
<li>With velocity and current position, calculate a new position</li>
<li>Dampen the velocity</li>
</ol>
<h2>Example:</h2>
<p>Here I have a velocity for the x coordinate as well as the y. I&#8217;m also experimenting with a z velocity. This adjusts the alpha and scale for depth perception. It doesn&#8217;t actually edit the depth or layer the dot shows up on the stage however&#8230; keyword here: experimenting. <img src='http://blog.circlecube.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_as3random_brownian_movement_809502127"
			class="flashmovie"
			width="550"
			height="550">
	<param name="movie" value="http://blog.circlecube.com/wp-content/uploads/2009/02/as3random_brownian_movement.swf" />
	<param name="wmode" value="transparent" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.circlecube.com/wp-content/uploads/2009/02/as3random_brownian_movement.swf"
			name="fm_as3random_brownian_movement_809502127"
			width="550"
			height="550">
		<param name="wmode" value="transparent" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<h2>Actionscript:</h2>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">//number of balls</span><br />
<span style="color: #000000; font-weight: bold;">var</span> numBalls:uint = <span style="color: #cc66cc;">50</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> defaultBallSize:uint = <span style="color: #cc66cc;">30</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//init</span><br />
makeDots<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> makeDots<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//create desired number of balls</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> ballNum:uint=<span style="color: #cc66cc;">0</span>; ballNum<span style="color: #66cc66;">&lt;</span>numBalls; ballNum++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> c1:<span style="color: #0066CC;">Number</span> = randomColor<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> c2:<span style="color: #0066CC;">Number</span> = randomColor<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//create ball</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> thisBall:<span style="color: #0066CC;">MovieClip</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">MovieClip</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>c1, .9<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>defaultBallSize<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">3</span>, c2, .9<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawCircle</span><span style="color: #66cc66;">&#40;</span>defaultBallSize, defaultBallSize, defaultBallSize<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span style="color: #66cc66;">&#40;</span>thisBall<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//coordinates</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">x</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: #66cc66;">*</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">y</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: #66cc66;">*</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//percieved depth</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">ballNum</span> = ballNum;<br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">depth</span> = ballNum<span style="color: #66cc66;">/</span>numBalls;<br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">scaleY</span> = thisBall.<span style="color: #006600;">scaleX</span> = thisBall.<span style="color: #006600;">alpha</span> = ballNum<span style="color: #66cc66;">/</span>numBalls;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//velocity</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">vx</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">vy</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">vz</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//ball animation</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, animateBall<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">var</span> dampen:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0.95</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> maxScale:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1.3</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> minScale:<span style="color: #0066CC;">Number</span> = .3;<br />
<span style="color: #000000; font-weight: bold;">var</span> maxAlpha:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1.3</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> minAlpha:<span style="color: #0066CC;">Number</span> = .3;<br />
<span style="color: #000000; font-weight: bold;">function</span> animateBall<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><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> thisBall:<span style="color: #0066CC;">Object</span> = <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>;<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//apply randomness to velocity</span><br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">vx</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: #66cc66;">*</span> <span style="color: #cc66cc;">0.2</span> - <span style="color: #cc66cc;">0.1</span>;<br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">vy</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: #66cc66;">*</span> <span style="color: #cc66cc;">0.2</span> - <span style="color: #cc66cc;">0.1</span>;<br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">vz</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: #66cc66;">*</span> <span style="color: #cc66cc;">0.002</span> - <span style="color: #cc66cc;">0.001</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">x</span> += thisBall.<span style="color: #006600;">vx</span>;<br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">y</span> += thisBall.<span style="color: #006600;">vy</span>;<br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">scaleX</span> = thisBall.<span style="color: #006600;">scaleY</span> += thisBall.<span style="color: #006600;">vz</span>;<br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">alpha</span> += thisBall.<span style="color: #006600;">vz</span>;<br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">vx</span> <span style="color: #66cc66;">*</span>= dampen;<br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">vy</span> <span style="color: #66cc66;">*</span>= dampen;<br />
&nbsp; &nbsp; thisBall.<span style="color: #006600;">vz</span> <span style="color: #66cc66;">*</span>= dampen;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>thisBall.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">0</span> - thisBall.<span style="color: #0066CC;">width</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>thisBall.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">0</span> - thisBall.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>thisBall.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">0</span> - thisBall.<span style="color: #0066CC;">height</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>thisBall.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">0</span> - thisBall.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>thisBall.<span style="color: #006600;">scaleX</span> <span style="color: #66cc66;">&gt;</span> maxScale<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">scaleX</span> = thisBall.<span style="color: #006600;">scaleY</span> = maxScale;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>thisBall.<span style="color: #006600;">scaleX</span> <span style="color: #66cc66;">&lt;</span> minScale<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">scaleX</span> = thisBall.<span style="color: #006600;">scaleY</span> = minScale;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>thisBall.<span style="color: #006600;">alpha</span> <span style="color: #66cc66;">&gt;</span> maxAlpha<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">alpha</span> = maxAlpha;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>thisBall.<span style="color: #006600;">alpha</span> <span style="color: #66cc66;">&lt;</span> minAlpha<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; thisBall.<span style="color: #006600;">alpha</span> = minAlpha;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> randomColor<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</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: #66cc66;">*</span> <span style="color: #cc66cc;">16777215</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<h2>Source:</h2>
<p><a class="download-box" href='http://blog.circlecube.com/wp-content/uploads/2009/02/as3random_brownian_movement.fla'>as3random_brownian_movement.fla</a></p>

<div class="sociable">
<div class="sociable_tagline">
<!-- <strong>Share and Enjoy:</strong> -->
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F&amp;title=Random%20Movement%20%7C%20Brownian%20revisited%20for%20as3&amp;notes=I%20have%20had%20feedback%20that%20certain%20random%20movements%20I%20program%20are%20a%20bit%20%22jumpy%22.%20Such%20as%20my%20old%20brownian%20movement%20tutorial%20and%20I%20really%20noticed%20it%20in%20my%20last%20tutorial%2C%20the%20parallax%203d%20depth%20effect%20tutorial.%20%20I%27ve%20been%20thinking%20about%20it%20and%20looking%20arou" title="del.icio.us"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F&amp;title=Random%20Movement%20%7C%20Brownian%20revisited%20for%20as3&amp;bodytext=I%20have%20had%20feedback%20that%20certain%20random%20movements%20I%20program%20are%20a%20bit%20%22jumpy%22.%20Such%20as%20my%20old%20brownian%20movement%20tutorial%20and%20I%20really%20noticed%20it%20in%20my%20last%20tutorial%2C%20the%20parallax%203d%20depth%20effect%20tutorial.%20%20I%27ve%20been%20thinking%20about%20it%20and%20looking%20arou" title="Digg"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Random%20Movement%20%7C%20Brownian%20revisited%20for%20as3&amp;body=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F" title="email"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F&amp;t=Random%20Movement%20%7C%20Brownian%20revisited%20for%20as3" title="Facebook"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F&amp;title=Random%20Movement%20%7C%20Brownian%20revisited%20for%20as3&amp;annotation=I%20have%20had%20feedback%20that%20certain%20random%20movements%20I%20program%20are%20a%20bit%20%22jumpy%22.%20Such%20as%20my%20old%20brownian%20movement%20tutorial%20and%20I%20really%20noticed%20it%20in%20my%20last%20tutorial%2C%20the%20parallax%203d%20depth%20effect%20tutorial.%20%20I%27ve%20been%20thinking%20about%20it%20and%20looking%20arou" title="Google Bookmarks"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F&amp;title=Random%20Movement%20%7C%20Brownian%20revisited%20for%20as3&amp;source=circlecube+Evan%26%23039%3Bs+Interactive+Actionscript+Exploration&amp;summary=I%20have%20had%20feedback%20that%20certain%20random%20movements%20I%20program%20are%20a%20bit%20%22jumpy%22.%20Such%20as%20my%20old%20brownian%20movement%20tutorial%20and%20I%20really%20noticed%20it%20in%20my%20last%20tutorial%2C%20the%20parallax%203d%20depth%20effect%20tutorial.%20%20I%27ve%20been%20thinking%20about%20it%20and%20looking%20arou" title="LinkedIn"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F&amp;title=Random%20Movement%20%7C%20Brownian%20revisited%20for%20as3" title="Mixx"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F&amp;partner=sociable" title="Print"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F&amp;partner=sociable" title="PDF"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F&amp;title=Random%20Movement%20%7C%20Brownian%20revisited%20for%20as3" title="StumbleUpon"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F" title="Technorati"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Random%20Movement%20%7C%20Brownian%20revisited%20for%20as3%20-%20http%3A%2F%2Fblog.circlecube.com%2F2009%2F02%2Ftutorial%2Frandom-movement-brownian-revisited-for-as3%2F" title="Twitter"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://blog.circlecube.com/feed/" title="RSS"><img src="http://blog.circlecube.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.circlecube.com/2009/02/tutorial/random-movement-brownian-revisited-for-as3/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 10/43 queries in 0.076 seconds using disk

Served from: blog.circlecube.com @ 2010-09-02 23:01:22 -->