<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Flex Blog</title>
	
	<link>http://www.flex-blog.com</link>
	<description>Examples, News and Other Stuff</description>
	<lastBuildDate>Sun, 25 Sep 2011 11:55:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/FlexBlog" /><feedburner:info uri="flexblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>FlexBlog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Spooky Frenzy – iPad Game</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/JzNMDzBrC0A/</link>
		<comments>http://www.flex-blog.com/spooky-frenzy-ipad-game/#comments</comments>
		<pubDate>Sun, 25 Sep 2011 11:52:28 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1551</guid>
		<description><![CDATA[Line Break Author: Arjan (47 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fspooky-frenzy-ipad-game%2F&amp;text=Spooky Frenzy &#8211; iPad Game&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Game,iOS,iPad,Objective-C"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(47 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p><br />
Hi all,</p>
<p>This is just a bit of shameless advertising from me. A while ago (around April). I started to learn Objective-C (iOS) development. Might seem strange as a Flex developer but it just seemed fun at the time. Shortly after that I had an idea in my head for a (iPad) game and started working with a friend to create it. He did the artwork, I did the coding stuff. <span id="more-1551"></span><br />
Now, after about six months of coding and drawing the game is available in the App Store.
<div width="500"><a href="http://itunes.apple.com/us/app/spooky-frenzy/id460709948?ls=1&#038;mt=8" title="App Store" target="_blank"><img src="http://www.spookyfrenzy.com/wp-content/themes/blacksapphire/images/appstore.png" alt="Spooky Frenzy in App Store" /></a></div>
<p>
The game is called <a href="http://www.spookyfrenzy.com" title="Spooky Frenzy" target="_blank">Spooky Frenzy</a>, and the idea is simple: fight off the Ghosts that are trying to get you. Each character requires it&#8217;s own gesture (swipe left, right, up down or pinch) to beat it. Check out the game&#8217;s <a href="http://www.spookyfrenzy.com" title="Spooky Frenzy" target="_blank">website</a> for more information. Check out the promo movie below for an impression of the game.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/16sp6bB3UrY" frameborder="0" allowfullscreen></iframe></p>


<p>No related posts.</p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/JzNMDzBrC0A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/spooky-frenzy-ipad-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/spooky-frenzy-ipad-game/</feedburner:origLink></item>
		<item>
		<title>Fountain Example</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/hC23Bbnv5XY/</link>
		<comments>http://www.flex-blog.com/fountain-example/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 13:31:10 +0000</pubDate>
		<dc:creator>Janez Feldin</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Guest Poster]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1528</guid>
		<description><![CDATA[Line Break Author: Janez Feldin (6 Articles) - Author Website Janez likes to experiment with flash in his own free time. His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding. Here is another example, this one more visually appealing (I hope). I made a class, Fountain, not [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/tinyurl-usage-with-flash-builder/' rel='bookmark' title='Permanent Link: TinyURL usage with Flash Builder'>TinyURL usage with Flash Builder</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Ffountain-example%2F&amp;text=Fountain Example&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=FlexBlog%3AFlex+Examples"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/janez/">Janez Feldin</a></b> <small>(6 Articles)</small> - <a href="http://www.flightbook.org/">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/a1e4d66aa5328baab2a61ca488b6db7d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Janez likes to experiment with flash in his own free time. 
His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding.</p>
</div><p></p>
<p>Here is another example, this one more visually appealing (I hope). I made a class, Fountain, not particulary usefull by itself, but can be used to teach some basics for handling bitmap and bitmapdata objects.</p>
<p><span id="more-1528"></span></p>
<p>I started by creating new flex project. Normal project for web application, and than created new class. I called it Fountain and extended UIComponent. UIComponent only so that bitmap can be added to it. Here is the code for that class:</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 />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 />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">FlexBlog</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">TimerEvent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filters</span>.<span style="color: #006600;">BlurFilter</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Point</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Timer</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #0066CC;">getTimer</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">UIComponent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Fountain <span style="color: #0066CC;">extends</span> UIComponent<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* declaration of bitmapdata which will show <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;our particles, and bitmap for our bitmapdata */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> bmd:BitmapData;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> bm:Bitmap;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* Array of objects. In each object <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;we store positions, speeds,...*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dp_particles:<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: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* delay for redrawing the particles <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(small number -&gt; fast motion, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;high number -&gt; slow motion */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> doMotionDelay:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">10</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* declaration of timer which calls <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;continuously the function to redraw <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;particles to bitmapdata */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> motion_timer:Timer;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* some of the variables to change the <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;visual appearance (try experimenting a bit) */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> maxParticles:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">300</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* defines how much particles can be created at once <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(it helps that particles doesn't appear in intervals) */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> maxParticlesAtOnce:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">15</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* x and y position where the particles will appear */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> sourcePoint:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">350</span>,<span style="color: #cc66cc;">700</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* defines the angle at wich particles will be shot */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> startAngle:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* particles can be shot at 45° different angle tan start angle */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> deltaAngle:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">45</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> maxStartSpeed:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">7</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> minStartSpeed:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">3</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* if the particles are bounding they never leave the visible area, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;so we need another criteria to know when to delete them. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If dampingFactor is set to 1 particles won't loose<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;speed when bouncing so they won't be deleted */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> minEndSpeed:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> gravityY:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0.1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> gravityX:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> blurFilter:BlurFilter = <span style="color: #000000; font-weight: bold;">new</span> BlurFilter<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1.5</span>,<span style="color: #cc66cc;">1.5</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* defines how much speed each particle keeps when <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bouncing of the walls (0 -&gt; no bouncing, 1 -&gt; continuous bouncing) */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> dampingFactor:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* array of colors for particles. Type color more times <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if you want more particles to have that color instead <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;of other colors. */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> colors:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span>0x0000FF,0x00FF00,0xFF0000,0x00FFFF,0xFF00FF,0xFFFF00<span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/* main function of the class, it gets called when <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;you define the class */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Fountain<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// since we extended UIComponent we need to inherit </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// all the properties of new UIcomponent. We achieve </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// that with calling super()</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// when the UIComponent initialize and is </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// fully created, we call the function appComplete</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FlexEvent.<span style="color: #006600;">CREATION_COMPLETE</span>, appComplete<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: #808080; font-style: italic;">/* function to add bitmapdata and bitmap to stage, and <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;to start our drawing by starting the motion_timer */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> appComplete<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// since we want the width and height of our fountain to </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// match the width and height set in mxml (or in actionscript </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// if we define new fountain with actionscript and not mxml) </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// for our component, we need to define new bitmapdata in </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// appComplete because before appcomplete gets called this.width </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// is not yet defined!</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bmd = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">width</span>,<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span>,<span style="color: #000000; font-weight: bold;">false</span>,0x000000<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// because we cannot add bitmapdata to stage (or another visual component) </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we need to create new bitmap that holds our bitmapdata object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bm = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// finnaly we can indirectly add our bitmapdata to UIComponent</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>bm<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we create new timer, add event listener to it so we </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// can continuously redraw particles</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; motion_timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span>doMotionDelay<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; motion_timer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, doMotion<span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// after everything is set, we start the timer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; motion_timer.<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; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// function that creates new particles when dp_particles </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// length is less than maxParticles</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createParticles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// some temp variables</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> newParticles:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// variable that stores tha number of particles </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// that will be created</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> temp_speed:<span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> temp_angle:<span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// if statment that checks if we can create all missing </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// particles at once (because of the maxParticlesAtOnce)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// here more particles are missing, than we allow them to </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// spawn at a time</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> maxParticles-dp_particles.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&gt;</span> maxParticlesAtOnce <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we get the random number which will define how much particles </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// will be created at once, because we can't create all the missing </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// particles, the random number must be lower than MaxParticlesAtOnce</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newParticles = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">ceil</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>maxParticlesAtOnce<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// maxParticles-dp_particles.length defines the number of missing </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// particles, and also makes sure that our random number is not larger </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// than this one</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newParticles = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">ceil</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: #66cc66;">&#40;</span>maxParticles-dp_particles.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</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; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// for loop to create new particles</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span>i=<span style="color: #cc66cc;">0</span>;i<span style="color: #66cc66;">&lt;</span>newParticles;i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// calculates random speed betwen minStartSpeed and maxStartSpeed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp_speed = minStartSpeed + <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: #66cc66;">&#40;</span>maxStartSpeed-minStartSpeed<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// calculate the starting angle (example: if we have startAngle=90 </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// and deltaAngle 45 the starting angle can be anywhere between 45 and 135</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// with Math.PI/180 transforms angle from ° to radians</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp_angle = <span style="color: #66cc66;">&#40;</span>-<span style="color: #cc66cc;">90</span>+startAngle+<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>deltaAngle-deltaAngle<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">PI</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">180</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// adds new object (particle) to our array of particles with </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// calculated starting values</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// with angle we split our speed to x and y direction (easier to draw </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// if we have x and y speed than speed and angle)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// for color we generate random integer between 0 and colors.length </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// to randomly select color from our array of colors</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp_particles.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>x: sourcePoint.<span style="color: #006600;">x</span>,y: sourcePoint.<span style="color: #006600;">y</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vx: temp_speed<span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span>temp_angle<span style="color: #66cc66;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vy: temp_speed<span style="color: #66cc66;">*</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span>temp_angle<span style="color: #66cc66;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">color</span>: colors<span style="color: #66cc66;">&#91;</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>colors.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#125;</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; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// function which redraws our particles on bitmapdata</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> doMotion<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:TimerEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// temporary variable to know if the particle we are </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// curently rendering was deleted</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> particle_deleted:<span style="color: #0066CC;">Boolean</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we apply the filter to bitmapdata to look cooler</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// also the filter is applied before the new position is calculated </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// because we want to blur the trail of the particle only and not </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// the particle itself</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bmd.<span style="color: #006600;">applyFilter</span><span style="color: #66cc66;">&#40;</span>bmd,bmd.<span style="color: #006600;">rect</span>,<span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>,blurFilter<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// if statment to check if there are any particles </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// missing. If there are we call createParticles() to create new ones</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> dp_particles.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&lt;</span> maxParticles <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createParticles<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; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// for loop to go trought all particles and recalculate their new </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// position, also checks if any particles are out of visible range </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// and delete them</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span>i=<span style="color: #cc66cc;">0</span>;i<span style="color: #66cc66;">&lt;</span>dp_particles.<span style="color: #0066CC;">length</span>;i++<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we set the particle_delted to false just to make sure </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// that it isn't set to true from last particle</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; particle_deleted = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we redraw curently rendering particle, and than </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// calculates new x and y position (the order could be reverse)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bmd.<span style="color: #006600;">setPixel</span><span style="color: #66cc66;">&#40;</span>dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span>,dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span>,dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">color</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// for new position we only add the speed to the curent position</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span> = dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span>+dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vx</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span> = dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span>+dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vy</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// two if statements to chek for bounce</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">||</span> dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// fro bounce from wall we reverse the direction </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// of speed and also multiply the speed with dampingFactor </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// so that we can set how particle bounce</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vx</span> = -dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vx</span> <span style="color: #66cc66;">*</span> dampingFactor;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span>= <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">||</span> dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vy</span> = -dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vy</span> <span style="color: #66cc66;">*</span> dampingFactor;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// if statement to check if particle has speed low enough </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// to be deleted or if it is out of visible range (actualy 5 pixels from &nbsp;sides, </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// because particles that are bouncing will never leave the visible area)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vx</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> minEndSpeed <span style="color: #66cc66;">&amp;&amp;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">abs</span><span style="color: #66cc66;">&#40;</span>dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vy</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> minEndSpeed <span style="color: #66cc66;">&amp;&amp;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">||</span> dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">width</span>-<span style="color: #cc66cc;">5</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">||</span> dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">||</span> dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">height</span>-<span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we remove the particle from out array with splice function. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// First parameter (i) is the index, the second one is the count </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// of the parameters that should be deleted, and next parameters </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// would be the values to be added to array (we don't need this one)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp_particles.<span style="color: #0066CC;">splice</span><span style="color: #66cc66;">&#40;</span>i,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; particle_deleted = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// we need to check that particle wasn't deleted. If the particle </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// would be deleted and we still applied the gravity effect, we </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// would apply the gravity effect to wrong particle or get an </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// error(if the deleted particle would be the last one in our array)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span>particle_deleted <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vx</span> += gravityX;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp_particles<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">vy</span> += gravityY;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</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; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>After we have created the class we only need to add it to the stage. I did it with mxml, I also added a form which had some sliders in it to quickly change settings.<br />
Here is the mxml code:</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 />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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:FlexBlog=<span style="color: #ff0000;">&quot;com.FlexBlog.*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minWidth=<span style="color: #ff0000;">&quot;955&quot;</span> minHeight=<span style="color: #ff0000;">&quot;600&quot;</span> xmlns:local=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #66cc66;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>-- we <span style="color: #0066CC;">add</span> our fountain <span style="color: #000000; font-weight: bold;">class</span> to <span style="color: #0066CC;">stage</span> <span style="color: #0066CC;">with</span> mxml. <br />
&nbsp; &nbsp; <span style="color: #006600;">Same</span> could be achieved <span style="color: #0066CC;">with</span> actionscript by <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> name_for_variable:Fountain = <span style="color: #000000; font-weight: bold;">new</span> Fountain<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>--<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>FlexBlog:Fountain id=<span style="color: #ff0000;">&quot;_fountain&quot;</span> x=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;700&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;700&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>-- Some form items to <span style="color: #0066CC;">set</span> the properties of the fountain. <br />
&nbsp; &nbsp; <span style="color: #b1b100;">each</span> form item is bind to some <span style="color: #0066CC;">variable</span> <span style="color: #b1b100;">in</span> our Fountain <span style="color: #000000; font-weight: bold;">class</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">this</span> is only <span style="color: #b1b100;">for</span> quick settings --<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:Form <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;280&quot;</span> bottom=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Max particles&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HSlider <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> minimum=<span style="color: #ff0000;">&quot;1&quot;</span> maximum=<span style="color: #ff0000;">&quot;1000&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value=<span style="color: #ff0000;">&quot;@{_fountain.maxParticles}&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Max new Particles&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HSlider <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> minimum=<span style="color: #ff0000;">&quot;1&quot;</span> maximum=<span style="color: #ff0000;">&quot;50&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value=<span style="color: #ff0000;">&quot;@{_fountain.maxParticlesAtOnce}&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Source point x&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HSlider id=<span style="color: #ff0000;">&quot;slider_source_x&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minimum=<span style="color: #ff0000;">&quot;0&quot;</span> maximum=<span style="color: #ff0000;">&quot;{_fountain.width}&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value=<span style="color: #ff0000;">&quot;200&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;change=<span style="color: #ff0000;">&quot;_fountain.sourcePoint.x = slider_source_x.value&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Source point y&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HSlider id=<span style="color: #ff0000;">&quot;slider_source_y&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minimum=<span style="color: #ff0000;">&quot;0&quot;</span> maximum=<span style="color: #ff0000;">&quot;{_fountain.height}&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value=<span style="color: #ff0000;">&quot;200&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;change=<span style="color: #ff0000;">&quot;_fountain.sourcePoint.y = slider_source_y.value&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Start angle&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HSlider <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> minimum=<span style="color: #ff0000;">&quot;0&quot;</span> maximum=<span style="color: #ff0000;">&quot;360&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value=<span style="color: #ff0000;">&quot;@{_fountain.startAngle}&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Delta angle&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HSlider <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> minimum=<span style="color: #ff0000;">&quot;0&quot;</span> maximum=<span style="color: #ff0000;">&quot;360&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value=<span style="color: #ff0000;">&quot;@{_fountain.deltaAngle}&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Gravity x&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HSlider <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> stepSize=<span style="color: #ff0000;">&quot;0.05&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minimum=<span style="color: #ff0000;">&quot;-1&quot;</span> maximum=<span style="color: #ff0000;">&quot;1&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value=<span style="color: #ff0000;">&quot;@{_fountain.gravityX}&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Gravity y&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HSlider <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> stepSize=<span style="color: #ff0000;">&quot;0.05&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minimum=<span style="color: #ff0000;">&quot;-1&quot;</span> maximum=<span style="color: #ff0000;">&quot;1&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value=<span style="color: #ff0000;">&quot;@{_fountain.gravityY}&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Damping factor&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HSlider <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> stepSize=<span style="color: #ff0000;">&quot;0.1&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minimum=<span style="color: #ff0000;">&quot;0&quot;</span> maximum=<span style="color: #ff0000;">&quot;1&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value=<span style="color: #ff0000;">&quot;@{_fountain.dampingFactor}&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>mx:Form<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Here is a screenshot of the fountain in action (its animating in the real example, ofcourse):</p>
<div style="width:600px">
<img src="http://www.flex-blog.com/samples/images/fountain.png" alt="Screenshot of the fountain in action" />
</div>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/tinyurl-usage-with-flash-builder/' rel='bookmark' title='Permanent Link: TinyURL usage with Flash Builder'>TinyURL usage with Flash Builder</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/hC23Bbnv5XY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/fountain-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/fountain-example/</feedburner:origLink></item>
		<item>
		<title>Reading &amp; Writing files in Adobe AIR</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/2E6LN2D2QRc/</link>
		<comments>http://www.flex-blog.com/reading-writing-files-in-adobe-air/#comments</comments>
		<pubDate>Tue, 03 May 2011 13:47:13 +0000</pubDate>
		<dc:creator>Janez Feldin</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[FileStream]]></category>
		<category><![CDATA[writeUTFBytes]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1515</guid>
		<description><![CDATA[Line Break Author: Janez Feldin (6 Articles) - Author Website Janez likes to experiment with flash in his own free time. His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding. This is a simple example that shows you how to create new class for reading and writing [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/adobe-air-sqlite-example/' rel='bookmark' title='Permanent Link: Adobe AIR SQLite Example'>Adobe AIR SQLite Example</a></li>
<li><a href='http://www.flex-blog.com/save-data-to-file-system-with-air-in-flex-4/' rel='bookmark' title='Permanent Link: Save Data to File System with AIR in Flex 4'>Save Data to File System with AIR in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/flex-blog-visits-adobe-max-2010/' rel='bookmark' title='Permanent Link: Flex Blog visits Adobe MAX 2010'>Flex Blog visits Adobe MAX 2010</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Freading-writing-files-in-adobe-air%2F&amp;text=Reading &#038; Writing files in Adobe AIR&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=AIR,File,FileStream,writeUTFBytes"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/janez/">Janez Feldin</a></b> <small>(6 Articles)</small> - <a href="http://www.flightbook.org/">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/a1e4d66aa5328baab2a61ca488b6db7d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Janez likes to experiment with flash in his own free time. 
His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding.</p>
</div><p></p>
<p>This is a simple example that shows you how to create new class for reading and writing text (.txt) files in Adobe AIR.</p>
<p><span id="more-1515"></span></p>
<p>We start of creating a new AIR project and an ActionScript Class. In my case I called the Class TextFile, but you can ofcourse name it what you like. Also note that I have put this class in com.FlexBlog.data package. </p>
<p>You can download my sample AIR application <a href="http://www.flex-blog.com/samples/sample53/TextFileTutorial.air">here</a> (View Source is enabled), or you can see full source below.</p>
<p>Below is the code of my TextFile class:</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 />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 /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">FlexBlog</span>.<span style="color: #0066CC;">data</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">File</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">FileMode</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">FileStream</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TextFile<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TextFile<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">//&nbsp; &nbsp; &nbsp; Writes the value parameter to file and replaces everything that was already in file (if existed)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> write<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span>,target_url:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//crates the new file class from string that contains target url...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> file:File = <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span>target_url<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//creates the new FileStream class used to actualy write/read/... the file...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> fs:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//opens the file in write method</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>file,FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//writes the text in file (UTFBytes are normal text...)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #006600;">writeUTFBytes</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//closes the file after it is done writing...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">//&nbsp; &nbsp; &nbsp; function to read the text file starting with startIndex and ending with endIndex</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> read<span style="color: #66cc66;">&#40;</span>target_url:<span style="color: #0066CC;">String</span>,startIndex:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>,endIndex:<span style="color: #0066CC;">int</span> = <span style="color: #0066CC;">int</span>.<span style="color: #0066CC;">MAX_VALUE</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> resaults:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> file:File = <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span>target_url<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> fs:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//here we open the file in reading mode... you cannot write anything in the file while it is opened in this mode</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>file,FileMode.<span style="color: #006600;">READ</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//we move FileStream class to our startIndex, so that when we read something from the file it starts at startIndex and not at the begining of the file... ( if startIndex is 0 than that is the begining of the file)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #0066CC;">position</span> = startIndex;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//we read the file and put it in resaults string... </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//we have to pass how many bytes we want to read to readUTFBytes. If we pass grater number than there are avaliable bytes we will get an error. That is why we take the minimum from bytesAvaliable and diference between start and end index...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resaults = fs.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">min</span><span style="color: #66cc66;">&#40;</span>endIndex-startIndex,fs.<span style="color: #006600;">bytesAvailable</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//after we have done everything we want we need to close the file...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//returns the string containing the text from startIndex to endIndex</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> resaults;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">//&nbsp; &nbsp; &nbsp; function used to append text to the end of text file. It is the same as write function, the only diference is that we open the file in APPEND mode and not WRITE. That means every time we write something AIR automatically writes that to the end of the file...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> append<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span>,target_url:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> file:File = <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span>target_url<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> fs:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>file,FileMode.<span style="color: #006600;">APPEND</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #006600;">writeUTFBytes</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">//&nbsp; &nbsp; &nbsp; function used to add text to desired position in file. It is the same as append, the diference is that we need to open file in UPDATE mode and we need to set position of our FileStream to desired position stored in startIndex parameter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span>,target_url:<span style="color: #0066CC;">String</span>,startIndex:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> file:File = <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span>target_url<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> fs:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span>file,FileMode.<span style="color: #006600;">UPDATE</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #0066CC;">position</span> = startIndex;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #006600;">writeUTFBytes</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>And here is the application&#8217;s mxml file, where you can see the example of how to call the functions in our class.</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 />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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:WindowedApplication xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span>-- Place non-visual elements <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">g</span>., services, value objects<span style="color: #66cc66;">&#41;</span> here --<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Write&quot;</span> bottom=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;87&quot;</span> click=<span style="color: #ff0000;">&quot;write(event)&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Read&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> bottom=<span style="color: #ff0000;">&quot;10&quot;</span> click=<span style="color: #ff0000;">&quot;read(event)&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Update&quot;</span> bottom=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;165&quot;</span> click=<span style="color: #ff0000;">&quot;update(event)&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Append&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;243&quot;</span> bottom=<span style="color: #ff0000;">&quot;10&quot;</span> click=<span style="color: #ff0000;">&quot;append(event)&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:TextArea id=<span style="color: #ff0000;">&quot;textArea&quot;</span> <span style="color: #0066CC;">left</span>=<span style="color: #ff0000;">&quot;10&quot;</span> top=<span style="color: #ff0000;">&quot;10&quot;</span> bottom=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;48%&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:FileSystemTree id=<span style="color: #ff0000;">&quot;file_tree&quot;</span> <span style="color: #0066CC;">right</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;48%&quot;</span> top=<span style="color: #ff0000;">&quot;10&quot;</span> bottom=<span style="color: #ff0000;">&quot;50&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">FlexBlog</span>.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">TextFile</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ObjectUtil</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> read<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; check if we have selected any file/folder</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> file_tree.<span style="color: #006600;">selectedPath</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; we create new file to check if it is the txt file...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> file:File = <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span>file_tree.<span style="color: #006600;">selectedPath</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> file.<span style="color: #006600;">extension</span> == <span style="color: #ff0000;">&quot;txt&quot;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #808080; font-style: italic;">//we check to see if file extension is txt if not we don't do anything otherwise we execute the desired action</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textArea.<span style="color: #0066CC;">text</span> = TextFile.<span style="color: #006600;">read</span><span style="color: #66cc66;">&#40;</span>file.<span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> write<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> file_tree.<span style="color: #006600;">selectedPath</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> file:File = <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span>file_tree.<span style="color: #006600;">selectedPath</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> file.<span style="color: #006600;">extension</span> == <span style="color: #ff0000;">&quot;txt&quot;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextFile.<span style="color: #006600;">write</span><span style="color: #66cc66;">&#40;</span>textArea.<span style="color: #0066CC;">text</span>,file.<span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> update<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> file_tree.<span style="color: #006600;">selectedPath</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> file:File = <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span>file_tree.<span style="color: #006600;">selectedPath</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> file.<span style="color: #006600;">extension</span> == <span style="color: #ff0000;">&quot;txt&quot;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//this will append in front of the file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextFile.<span style="color: #006600;">update</span><span style="color: #66cc66;">&#40;</span>textArea.<span style="color: #0066CC;">text</span>,file.<span style="color: #0066CC;">url</span>,<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> append<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> file_tree.<span style="color: #006600;">selectedPath</span> <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> file:File = <span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span>file_tree.<span style="color: #006600;">selectedPath</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> file.<span style="color: #006600;">extension</span> == <span style="color: #ff0000;">&quot;txt&quot;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextFile.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span>textArea.<span style="color: #0066CC;">text</span>,file.<span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:WindowedApplication<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/adobe-air-sqlite-example/' rel='bookmark' title='Permanent Link: Adobe AIR SQLite Example'>Adobe AIR SQLite Example</a></li>
<li><a href='http://www.flex-blog.com/save-data-to-file-system-with-air-in-flex-4/' rel='bookmark' title='Permanent Link: Save Data to File System with AIR in Flex 4'>Save Data to File System with AIR in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/flex-blog-visits-adobe-max-2010/' rel='bookmark' title='Permanent Link: Flex Blog visits Adobe MAX 2010'>Flex Blog visits Adobe MAX 2010</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/2E6LN2D2QRc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/reading-writing-files-in-adobe-air/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/reading-writing-files-in-adobe-air/</feedburner:origLink></item>
		<item>
		<title>CheckBox in List using MobileIconItemRenderer for Flex Mobile</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/G_wGjOj9Ivw/</link>
		<comments>http://www.flex-blog.com/checkbox-in-list-using-mobileiconitemrenderer-for-flex-mobile/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 18:26:08 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[CheckBox]]></category>
		<category><![CDATA[Flex Mobile]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[MobileIconItemRenderer]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1480</guid>
		<description><![CDATA[Line Break Author: Arjan (47 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/data-dependent-decoratorclass-in-mobileiconitemrenderer-example/' rel='bookmark' title='Permanent Link: Data Dependent decoratorClass in MobileIconItemRenderer Example'>Data Dependent decoratorClass in MobileIconItemRenderer Example</a></li>
<li><a href='http://www.flex-blog.com/list-directory-with-air-in-flex-4/' rel='bookmark' title='Permanent Link: List Directory with AIR in Flex 4'>List Directory with AIR in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/view-navigation-in-a-mobile-flex-application/' rel='bookmark' title='Permanent Link: View Navigation in a Mobile Flex Application'>View Navigation in a Mobile Flex Application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fcheckbox-in-list-using-mobileiconitemrenderer-for-flex-mobile%2F&amp;text=CheckBox in List using MobileIconItemRenderer for Flex Mobile&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=CheckBox,Flex+Mobile,List,Mobile,MobileIconItemRenderer"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(47 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p><br />
In my previous post I showed you how you can set a decoratorClass of a MobileIconItemRenderer depending on the data of the list item. The example made me wonder if it was possible to display a CheckBox in a MobileIconItemRenderer. Turns out it&#8217;s pretty easy to do so.<br />
<span id="more-1480"></span></p>
<p>First lets create a new Flex Mobile project, I named it CheckboxInMobileIconItemRenderer. For this example we are going to store our data in a model class. By using a model class we can retain our data when we navigate to other views, if we don&#8217;t do that, the view and any data, variables that are in the view get trashed by the runtime.</p>
<p>Create a new package called model. After that, create a new ActionScript class in the model package. Call it AppModel.as. To make sure the application always refers to the same model instance, we are going to simulate singleton behaviour. I&#8217;m not going to explain this here, it&#8217;s quite easy to see how this works. Basically the class keeps track of a static instance variable and only instantiates this one time. After that, it keeps returning this instance when an instance is requested by using the getInstance() method:</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 />23<br />24<br />25<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package model<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AppModel<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> _instance:AppModel;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> items:ArrayCollection;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AppModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</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: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:AppModel<br />
&nbsp; &nbsp; &nbsp; &nbsp; <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> _instance == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _instance = <span style="color: #000000; font-weight: bold;">new</span> AppModel<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;">return</span> _instance;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now navigate to the Home view Flash Builder created for you in the views package, add the following code:</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 />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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:View xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #ff0000;">&quot;Select items:&quot;</span> initialize=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VerticalLayout gap=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> model.<span style="color: #006600;">AppModel</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> appModel:AppModel;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Generate dummy data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Get model instance</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appModel = AppModel.<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// If items is empty, create dummy data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>appModel.<span style="color: #006600;">items</span> == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appModel.<span style="color: #006600;">items</span> = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &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:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">10</span>; i++ <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj = <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 />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #0066CC;">Name</span> = <span style="color: #ff0000;">&quot;List item &quot;</span> + i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">Description</span> = <span style="color: #ff0000;">&quot;Description &quot;</span> + i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #0066CC;">Status</span> = <span style="color: #66cc66;">&#40;</span>i <span style="color: #66cc66;">%</span> <span style="color: #cc66cc;">2</span> == <span style="color: #cc66cc;">0</span> ? <span style="color: #000000; font-weight: bold;">true</span> : <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; appModel.<span style="color: #006600;">items</span>.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">List</span> id=<span style="color: #ff0000;">&quot;myList&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{appModel.items}&quot;</span> labelField=<span style="color: #ff0000;">&quot;Name&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:View<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Create a new MXML component in the views package, name it CheckboxListItemRenderer and make sure its based on MobileIconItemRenderer. Add the following code:</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 />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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:MobileIconItemRenderer xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageField=<span style="color: #ff0000;">&quot;Description&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initialize=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">components</span>.<span style="color: #006600;">Application</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">components</span>.<span style="color: #006600;">CheckBox</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">components</span>.<span style="color: #0066CC;">List</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> cb:CheckBox;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span>cb <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cb = <span style="color: #000000; font-weight: bold;">new</span> CheckBox<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cb.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, handleClick<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cb.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">parent</span>.<span style="color: #006600;">width</span>-<span style="color: #cc66cc;">70</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cb.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">25</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> cb <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleClick<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">Status</span> = cb.<span style="color: #006600;">selected</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>value <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #0066CC;">data</span> = value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cb.<span style="color: #006600;">selected</span> = value.<span style="color: #0066CC;">Status</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
<br />
<span style="color: #66cc66;">&lt;/</span>s:MobileIconItemRenderer<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Navigate to the home view and set the itemRenderer of the List in the home view to be the one we just created:</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 /></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: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">List</span> id=<span style="color: #ff0000;">&quot;myList&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{appModel.items}&quot;</span> labelField=<span style="color: #ff0000;">&quot;Name&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> itemRenderer=<span style="color: #ff0000;">&quot;views.CheckboxListItemRenderer&quot;</span><span style="color: #66cc66;">/&gt;</span></div></td></tr></tbody></table></div>
<p>Test the application. You should see something like this:</p>
<div style="width:600px;" align="center">
<img src="http://www.flex-blog.com/samples/sample52/HomeView.png" alt="Home View" />
</div>
<p>Create a second view in the views package, call it SelectedItemsView. Add the following code:</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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:View xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> title=<span style="color: #ff0000;">&quot;You selected:&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VerticalLayout gap=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">List</span> id=<span style="color: #ff0000;">&quot;selectedItems&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{data}&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> labelField=<span style="color: #ff0000;">&quot;Name&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> label=<span style="color: #ff0000;">&quot;Previous&quot;</span> click=<span style="color: #ff0000;">&quot;navigator.popView()&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:View<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Go back to the Home view and add the following button:</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: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> label=<span style="color: #ff0000;">&quot;Next&quot;</span> click=<span style="color: #ff0000;">&quot;next()&quot;</span><span style="color: #66cc66;">/&gt;</span></div></td></tr></tbody></table></div>
<p>Add the following method in the script section:</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 /></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;">// Navigate to Selected Items View</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> next<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Get all selected items</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> selectedItems:ArrayCollection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> <span style="color: #b1b100;">in</span> appModel.<span style="color: #006600;">items</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> obj.<span style="color: #0066CC;">Status</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selectedItems.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Navigate to the SelectedItemsView with selectedItems as data</span><br />
&nbsp; &nbsp; navigator.<span style="color: #006600;">pushView</span><span style="color: #66cc66;">&#40;</span> SelectedItemsView, selectedItems <span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now you can navigate between the two views. Notice that the application &#8220;remembers&#8221; the selected items when you navigate back and forth between views. If you keep the items ArrayCollection as a variable in the view, it gets destroyed when you navigate away from the view. Screens of the finished application:</p>
<div style="width:300px;float:left;">
<img src="http://www.flex-blog.com/samples/sample52/HomeViewFinished.png" alt="Home View Finished" />
</div>
<div style="width:300px;float:left;">
<img src="http://www.flex-blog.com/samples/sample52/SelectedItemsView.png" alt="Selected Items View" />
</div>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/data-dependent-decoratorclass-in-mobileiconitemrenderer-example/' rel='bookmark' title='Permanent Link: Data Dependent decoratorClass in MobileIconItemRenderer Example'>Data Dependent decoratorClass in MobileIconItemRenderer Example</a></li>
<li><a href='http://www.flex-blog.com/list-directory-with-air-in-flex-4/' rel='bookmark' title='Permanent Link: List Directory with AIR in Flex 4'>List Directory with AIR in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/view-navigation-in-a-mobile-flex-application/' rel='bookmark' title='Permanent Link: View Navigation in a Mobile Flex Application'>View Navigation in a Mobile Flex Application</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/G_wGjOj9Ivw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/checkbox-in-list-using-mobileiconitemrenderer-for-flex-mobile/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/checkbox-in-list-using-mobileiconitemrenderer-for-flex-mobile/</feedburner:origLink></item>
		<item>
		<title>Data Dependent decoratorClass in MobileIconItemRenderer Example</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/a82LPQBQ4sk/</link>
		<comments>http://www.flex-blog.com/data-dependent-decoratorclass-in-mobileiconitemrenderer-example/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 15:12:17 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[decoratorClass]]></category>
		<category><![CDATA[Flex Mobile]]></category>
		<category><![CDATA[Icon]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[MobileIconItemRenderer]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1466</guid>
		<description><![CDATA[Line Break Author: Arjan (47 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/checkbox-in-list-using-mobileiconitemrenderer-for-flex-mobile/' rel='bookmark' title='Permanent Link: CheckBox in List using MobileIconItemRenderer for Flex Mobile'>CheckBox in List using MobileIconItemRenderer for Flex Mobile</a></li>
<li><a href='http://www.flex-blog.com/data-dependant-tree-icon-with-tree-in-advanceddatagrid-with-iconfunction/' rel='bookmark' title='Permanent Link: Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction'>Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction</a></li>
<li><a href='http://www.flex-blog.com/images-in-datagrid-depending-on-data/' rel='bookmark' title='Permanent Link: Images in DataGrid depending on data'>Images in DataGrid depending on data</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fdata-dependent-decoratorclass-in-mobileiconitemrenderer-example%2F&amp;text=Data Dependent decoratorClass in MobileIconItemRenderer Example&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=decoratorClass,Flex+Mobile,Icon,Mobile,MobileIconItemRenderer"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(47 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p></p>
<p>This small example shows you how you can create a List that has uses a MobileIconItemRenderer that has a decoratorClass that depends on the data.</p>
<p><span id="more-1466"></span></p>
<p>Create a new Mobile Flex Project, give it a name and click finish. Navigator to the default home view and add a list, dataprovider and a method that creates some dummy data:</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 />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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:View xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #ff0000;">&quot;MobileIconItemRenderer&quot;</span> initialize=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> items:ArrayCollection;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Generate dummy data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; items = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &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:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">10</span>; i++ <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj = <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 />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #0066CC;">Name</span> = <span style="color: #ff0000;">&quot;List item &quot;</span> + i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #006600;">Description</span> = <span style="color: #ff0000;">&quot;Description &quot;</span> + i;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.<span style="color: #0066CC;">Status</span> = i <span style="color: #66cc66;">%</span> <span style="color: #cc66cc;">3</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; items.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">List</span> id=<span style="color: #ff0000;">&quot;myList&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{items}&quot;</span> labelField=<span style="color: #ff0000;">&quot;Name&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> itemRenderer=<span style="color: #ff0000;">&quot;views.ListItemRenderer&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:View<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>First create an assets package and add three icons to it, you can find the icons <a href="http://www.flex-blog.com/samples/sample51/icons/">here</a>.</p>
<p>You can see that the list uses an itemRenderer, create it by creating a new MXML component that&#8217;s based on MobileIconItemRenderer in the views package, name it ListItemRenderer. Add the following code to it:</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 />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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:MobileIconItemRenderer xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageField=<span style="color: #ff0000;">&quot;Description&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Embed &quot;Done&quot; icon</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/done.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconDone:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Embed &quot;Open&quot; icon</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/open.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconOpen:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Embed &quot;Progress&quot; icon</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/progress.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> iconInProgress:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Set decoratorClass depending on status</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>value <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #0066CC;">data</span> = value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">status</span>:<span style="color: #0066CC;">int</span> &nbsp;= value.<span style="color: #0066CC;">Status</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> icon:<span style="color: #000000; font-weight: bold;">Class</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">status</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">0</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; icon = iconOpen;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; icon = iconInProgress;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; icon = iconDone;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">decoratorClass</span> = icon;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:MobileIconItemRenderer<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Now run your application. If everything is ok, you should see a different icon for each of the statusses (1,2 or 3).</p>
<div style="width: 400px; margin-left: auto; margin-right: auto;">
<img src="http://www.flex-blog.com/samples/sample51/MobileIconItemRenderer.png" alt="Screenshot of the MobileIconItemRenderer" />
</div>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/checkbox-in-list-using-mobileiconitemrenderer-for-flex-mobile/' rel='bookmark' title='Permanent Link: CheckBox in List using MobileIconItemRenderer for Flex Mobile'>CheckBox in List using MobileIconItemRenderer for Flex Mobile</a></li>
<li><a href='http://www.flex-blog.com/data-dependant-tree-icon-with-tree-in-advanceddatagrid-with-iconfunction/' rel='bookmark' title='Permanent Link: Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction'>Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction</a></li>
<li><a href='http://www.flex-blog.com/images-in-datagrid-depending-on-data/' rel='bookmark' title='Permanent Link: Images in DataGrid depending on data'>Images in DataGrid depending on data</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/a82LPQBQ4sk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/data-dependent-decoratorclass-in-mobileiconitemrenderer-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/data-dependent-decoratorclass-in-mobileiconitemrenderer-example/</feedburner:origLink></item>
		<item>
		<title>Flex 4 Resize Effect Example</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/F4xsdYcgrjA/</link>
		<comments>http://www.flex-blog.com/flex-4-resize-effect-example/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 20:04:34 +0000</pubDate>
		<dc:creator>Roelof</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Fade]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[resizeEffect]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1454</guid>
		<description><![CDATA[Line Break Author: Roelof (13 Articles) - Author Website Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer or traveling. He is also the co-owner of Flex-Blog.com. YH4AAZEM8PF5 This example shows you how to use the resizeEffect along with [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/flex-4-effect-example-sliding-text-using-the-move-effect/' rel='bookmark' title='Permanent Link: Flex 4 Effect Example: Sliding text using the Move Effect'>Flex 4 Effect Example: Sliding text using the Move Effect</a></li>
<li><a href='http://www.flex-blog.com/flex-custom-event-example/' rel='bookmark' title='Permanent Link: Flex Custom Event Example'>Flex Custom Event Example</a></li>
<li><a href='http://www.flex-blog.com/image-as-button-in-a-datagrid/' rel='bookmark' title='Permanent Link: Image as Button in a DataGrid'>Image as Button in a DataGrid</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fflex-4-resize-effect-example%2F&amp;text=Flex 4 Resize Effect Example&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Fade,Flex,resizeEffect"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/roelof/">Roelof</a></b> <small>(13 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/2caba20bc811d080f88174249b682d14?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer or traveling. He is also the co-owner of Flex-Blog.com.</p>
</div><p></p>
<p>YH4AAZEM8PF5 This example shows you how to use the <i>resizeEffect</i> along with a simple fade effect to make it look smooth!</p>
<p><span id="more-1454"></span></p>
<p>The Resize Effect is pretty straight forward, there are just a few simple rules:</p>
<ul>
<li>Make sure the object you want to resize has a width and height of 100%.</li>
<li>Create enough space within your application.</li>
</ul>
<p>Below is the example with View Source enabled:<br />
<iframe src="http://www.flex-blog.com/samples/sample50/ResizeEffectExample.html" width="100%" frameborder="0" height="300"></iframe></p>
<p>And here is the full source:</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 />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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;300&quot;</span> &nbsp;viewSourceURL=<span style="color: #ff0000;">&quot;srcview/index.html&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> addImage<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myImage.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myImage.<span style="color: #006600;">includeInLayout</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> removeImage<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myImage.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myImage.<span style="color: #006600;">includeInLayout</span> = <span style="color: #000000; font-weight: bold;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:Fade <span style="color: #0066CC;">duration</span>=<span style="color: #ff0000;">&quot;2000&quot;</span> alphaFrom=<span style="color: #ff0000;">&quot;0&quot;</span> alphaTo=<span style="color: #ff0000;">&quot;1&quot;</span> id=<span style="color: #ff0000;">&quot;fadeIn&quot;</span> <span style="color: #66cc66;">/&gt;</span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:Fade <span style="color: #0066CC;">duration</span>=<span style="color: #ff0000;">&quot;100&quot;</span> alphaFrom=<span style="color: #ff0000;">&quot;1&quot;</span> alphaTo=<span style="color: #ff0000;">&quot;0&quot;</span> id=<span style="color: #ff0000;">&quot;fadeOut&quot;</span> <span style="color: #66cc66;">/&gt;</span>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HorizontalLayout horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VGroup verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HGroup verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;10&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Add image!&quot;</span> click=<span style="color: #ff0000;">&quot;addImage(event)&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Remove image!&quot;</span> click=<span style="color: #ff0000;">&quot;removeImage(event)&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:HGroup<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HGroup verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:Panel <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> title=<span style="color: #ff0000;">&quot;I'm a resizable Panel!&quot;</span> resizeEffect=<span style="color: #ff0000;">&quot;Resize&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:Image id=<span style="color: #ff0000;">&quot;myImage&quot;</span> source=<span style="color: #ff0000;">&quot;http://www.flex-blog.com/wp-content/themes/revolution_news-21/images/header.png&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">visible</span>=<span style="color: #ff0000;">&quot;false&quot;</span> includeInLayout=<span style="color: #ff0000;">&quot;false&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showEffect=<span style="color: #ff0000;">&quot;{fadeIn}&quot;</span> hideEffect=<span style="color: #ff0000;">&quot;{fadeOut}&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:Panel<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:HGroup<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:VGroup<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>If you have a question, leave a comment or post it in our <a href="http://www.flex-blog.com/forum/">flex forum</a>!</p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/flex-4-effect-example-sliding-text-using-the-move-effect/' rel='bookmark' title='Permanent Link: Flex 4 Effect Example: Sliding text using the Move Effect'>Flex 4 Effect Example: Sliding text using the Move Effect</a></li>
<li><a href='http://www.flex-blog.com/flex-custom-event-example/' rel='bookmark' title='Permanent Link: Flex Custom Event Example'>Flex Custom Event Example</a></li>
<li><a href='http://www.flex-blog.com/image-as-button-in-a-datagrid/' rel='bookmark' title='Permanent Link: Image as Button in a DataGrid'>Image as Button in a DataGrid</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/F4xsdYcgrjA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/flex-4-resize-effect-example/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/flex-4-resize-effect-example/</feedburner:origLink></item>
		<item>
		<title>Jump to next field using the Focus Manager</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/GBvcCZlkJr8/</link>
		<comments>http://www.flex-blog.com/jump-to-next-field-using-the-focus-manager/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 19:16:35 +0000</pubDate>
		<dc:creator>Roelof</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[FocusManager]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1442</guid>
		<description><![CDATA[Line Break Author: Roelof (13 Articles) - Author Website Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer or traveling. He is also the co-owner of Flex-Blog.com. The following example shows you how to use the FocusManager and how [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fjump-to-next-field-using-the-focus-manager%2F&amp;text=Jump to next field using the Focus Manager&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=FocusManager"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/roelof/">Roelof</a></b> <small>(13 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/2caba20bc811d080f88174249b682d14?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer or traveling. He is also the co-owner of Flex-Blog.com.</p>
</div><p></p>
<p>The following example shows you how to use the FocusManager and how to set the focus to a TextInput using the setFocus() method.</p>
<p><span id="more-1442"></span></p>
<p>In this example you can fill you birthday (MM/DD/YYYY) and the focus will jump to the next field automatically. (View source is enabled or scroll down for full source code.)</p>
<p><iframe src="http://www.flex-blog.com/samples/sample49/JumpToNextFieldExample.html" width="100%" frameborder="0" height="100"></iframe></p>
<p>And here is the full source:</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 />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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">events</span>.<span style="color: #006600;">TextOperationEvent</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> checkLengthAndFocus<span style="color: #66cc66;">&#40;</span>event:TextOperationEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> event.<span style="color: #006600;">currentTarget</span>.<span style="color: #006600;">id</span> == <span style="color: #ff0000;">&quot;month&quot;</span> <span style="color: #66cc66;">&amp;&amp;</span> event.<span style="color: #006600;">currentTarget</span>.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">length</span> == <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; focusManager.<span style="color: #0066CC;">setFocus</span><span style="color: #66cc66;">&#40;</span> day <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> event.<span style="color: #006600;">currentTarget</span>.<span style="color: #006600;">id</span> == <span style="color: #ff0000;">&quot;day&quot;</span> <span style="color: #66cc66;">&amp;&amp;</span> event.<span style="color: #006600;">currentTarget</span>.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">length</span> == <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; focusManager.<span style="color: #0066CC;">setFocus</span><span style="color: #66cc66;">&#40;</span> year <span style="color: #66cc66;">&#41;</span>;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VGroup <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> paddingBottom=<span style="color: #ff0000;">&quot;5&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;5&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Fill in your birthday (MM/DD/YYYY)&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HGroup <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #66cc66;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:TextInput id=<span style="color: #ff0000;">&quot;month&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;23&quot;</span> change=<span style="color: #ff0000;">&quot;checkLengthAndFocus(event)&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:TextInput id=<span style="color: #ff0000;">&quot;day&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;23&quot;</span> change=<span style="color: #ff0000;">&quot;checkLengthAndFocus(event)&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:TextInput id=<span style="color: #ff0000;">&quot;year&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;46&quot;</span> <span style="color: #0066CC;">maxChars</span>=<span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:HGroup<span style="color: #66cc66;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:VGroup<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>


<p>No related posts.</p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/GBvcCZlkJr8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/jump-to-next-field-using-the-focus-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/jump-to-next-field-using-the-focus-manager/</feedburner:origLink></item>
		<item>
		<title>Searching Data using a Class Example</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/TNwuJ5yXOh4/</link>
		<comments>http://www.flex-blog.com/searching-data-using-a-class-example/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 18:50:12 +0000</pubDate>
		<dc:creator>Janez Feldin</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[DataGrid]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1437</guid>
		<description><![CDATA[Line Break Author: Janez Feldin (6 Articles) - Author Website Janez likes to experiment with flash in his own free time. His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding. I know there are alot already written classes for data searching and sorting, but I wrote this [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/images-in-datagrid-depending-on-data/' rel='bookmark' title='Permanent Link: Images in DataGrid depending on data'>Images in DataGrid depending on data</a></li>
<li><a href='http://www.flex-blog.com/save-data-to-file-system-with-air-in-flex-4/' rel='bookmark' title='Permanent Link: Save Data to File System with AIR in Flex 4'>Save Data to File System with AIR in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/style-advanceddatagrid-depending-on-data-example/' rel='bookmark' title='Permanent Link: Style AdvancedDataGrid depending on data example'>Style AdvancedDataGrid depending on data example</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fsearching-data-using-a-class-example%2F&amp;text=Searching Data using a Class Example&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Class,DataGrid"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/janez/">Janez Feldin</a></b> <small>(6 Articles)</small> - <a href="http://www.flightbook.org/">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/a1e4d66aa5328baab2a61ca488b6db7d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Janez likes to experiment with flash in his own free time. 
His other hobbies are playing volleyball, listening to the music, watching movies and above all else, paragliding.</p>
</div><p><br />
I know there are alot already written classes for data searching and sorting, but I wrote this example anyway, because if you know how things are done you can customize/change it for your needs.<br />
<span id="more-1437"></span><br />
The result (view source is enabled, with loads of comments!):</p>
<p><iframe src="http://www.flex-blog.com/samples/sample48/Main.html" width="100%" frameborder="0" height="300"></iframe></p>
<p>This is just a simple tutorial, how to make our own component that extends TextInput, for searching the data in datagrid. So to get started you need to create new flex project and after that create new Actionscript class that extends spark.components.TextInput and you are good to go.</p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/images-in-datagrid-depending-on-data/' rel='bookmark' title='Permanent Link: Images in DataGrid depending on data'>Images in DataGrid depending on data</a></li>
<li><a href='http://www.flex-blog.com/save-data-to-file-system-with-air-in-flex-4/' rel='bookmark' title='Permanent Link: Save Data to File System with AIR in Flex 4'>Save Data to File System with AIR in Flex 4</a></li>
<li><a href='http://www.flex-blog.com/style-advanceddatagrid-depending-on-data-example/' rel='bookmark' title='Permanent Link: Style AdvancedDataGrid depending on data example'>Style AdvancedDataGrid depending on data example</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/TNwuJ5yXOh4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/searching-data-using-a-class-example/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/searching-data-using-a-class-example/</feedburner:origLink></item>
		<item>
		<title>Flex Mobile: Two finger tap gesture to toggle actionBar visibility in a View (AIR for Android)</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/QxLTJoUkzxE/</link>
		<comments>http://www.flex-blog.com/flex-mobile-two-finger-tap-gesture-to-toggle-actionbar-visibility-in-a-view-air-for-android/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 19:16:06 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Flex Mobile]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1399</guid>
		<description><![CDATA[Line Break Author: Arjan (47 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/using-swipe-gestures-in-mobile-flex-application-air-for-android/' rel='bookmark' title='Permanent Link: Using Swipe Gestures in Mobile Flex Application (AIR for Android)'>Using Swipe Gestures in Mobile Flex Application (AIR for Android)</a></li>
<li><a href='http://www.flex-blog.com/tabbedmobileapplication-example-in-flex-mobile-air-for-android/' rel='bookmark' title='Permanent Link: TabbedMobileApplication Example in Flex Mobile (AIR for Android)'>TabbedMobileApplication Example in Flex Mobile (AIR for Android)</a></li>
<li><a href='http://www.flex-blog.com/view-navigation-in-a-mobile-flex-application/' rel='bookmark' title='Permanent Link: View Navigation in a Mobile Flex Application'>View Navigation in a Mobile Flex Application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Fflex-mobile-two-finger-tap-gesture-to-toggle-actionbar-visibility-in-a-view-air-for-android%2F&amp;text=Flex Mobile: Two finger tap gesture to toggle actionBar visibility in a View (AIR for Android)&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Flex+Mobile"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(47 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p><br />
Here&#8217;s a small example to show you how you can toggle the visibility of the actionBar of a View in a mobile flex application. I thought about a gesture that would be nice to use for showing and hiding the actionBar and thought that the two finger tap would be a good candidate for the job.<br />
<span id="more-1399"></span><br />
Basically all I did for this little example was creating a new Flex Mobile project. After that I modified the View tag of the View that&#8217;s created for you when you create a new MobileApplication project like this:</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 /></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: #66cc66;">&lt;</span>s:View xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; actionBarVisible=<span style="color: #ff0000;">&quot;{actionBarVis}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> title=<span style="color: #ff0000;">&quot;Home&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; gestureTwoFingerTap=<span style="color: #ff0000;">&quot;toggleActionBar(event)&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:View<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>As you can see I binded the actionBarVisible to a variable called actionBarVis and I put an event handler on the gestureTwoFingerTap event. The script section to facilitate this:</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 /></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: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> actionBarVis:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Handle gesture event</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> toggleActionBar<span style="color: #66cc66;">&#40;</span>event:GestureEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; actionBarVis = <span style="color: #66cc66;">!</span>actionBarVis;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>To make it a little bit more interesting I created a big label that changes color and text when the actionBar visibility changes. No need for it whatsoever but it just spices up this dull example a tiny bit.</p>
<p>My complete code for the View:</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 />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:View xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; actionBarVisible=<span style="color: #ff0000;">&quot;{actionBarVis}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> title=<span style="color: #ff0000;">&quot;Home&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; gestureTwoFingerTap=<span style="color: #ff0000;">&quot;toggleActionBar(event)&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VerticalLayout verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> actionBarVis:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Handle gesture event</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> toggleActionBar<span style="color: #66cc66;">&#40;</span>event:GestureEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; actionBarVis = <span style="color: #66cc66;">!</span>actionBarVis;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;{actionBarVis ? 'ActionBar Visible' : 'ActionBar Not Visible'}&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fontSize=<span style="color: #ff0000;">&quot;40&quot;</span> fontWeight=<span style="color: #ff0000;">&quot;bold&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;{actionBarVis ? 0x00FF00 : 0xFF0000}&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:View<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Screens:</p>
<div style="width: 500px;text-align:center;"><img src="http://www.flex-blog.com/samples/images/actionbar1.png" alt="Action Bar Visible" hspace="10"/><img src="http://www.flex-blog.com/samples/images/actionbar2.png" alt="Action Bar Invisible" /></div>
<p></br></p>
<p>That&#8217;s it. Now you can toggle the actionBar visibility using a two finger tap. Hopefully you can test it on your own Android 2.2 (or higher) device.</p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/using-swipe-gestures-in-mobile-flex-application-air-for-android/' rel='bookmark' title='Permanent Link: Using Swipe Gestures in Mobile Flex Application (AIR for Android)'>Using Swipe Gestures in Mobile Flex Application (AIR for Android)</a></li>
<li><a href='http://www.flex-blog.com/tabbedmobileapplication-example-in-flex-mobile-air-for-android/' rel='bookmark' title='Permanent Link: TabbedMobileApplication Example in Flex Mobile (AIR for Android)'>TabbedMobileApplication Example in Flex Mobile (AIR for Android)</a></li>
<li><a href='http://www.flex-blog.com/view-navigation-in-a-mobile-flex-application/' rel='bookmark' title='Permanent Link: View Navigation in a Mobile Flex Application'>View Navigation in a Mobile Flex Application</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/QxLTJoUkzxE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/flex-mobile-two-finger-tap-gesture-to-toggle-actionbar-visibility-in-a-view-air-for-android/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/flex-mobile-two-finger-tap-gesture-to-toggle-actionbar-visibility-in-a-view-air-for-android/</feedburner:origLink></item>
		<item>
		<title>TabbedMobileApplication Example in Flex Mobile (AIR for Android)</title>
		<link>http://feedproxy.google.com/~r/FlexBlog/~3/tD4lsdXHGv8/</link>
		<comments>http://www.flex-blog.com/tabbedmobileapplication-example-in-flex-mobile-air-for-android/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 17:31:09 +0000</pubDate>
		<dc:creator>Arjan</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Flex Mobile]]></category>

		<guid isPermaLink="false">http://www.flex-blog.com/?p=1389</guid>
		<description><![CDATA[Line Break Author: Arjan (47 Articles) - Author Website Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and [...]


Related posts:<ol><li><a href='http://www.flex-blog.com/using-swipe-gestures-in-mobile-flex-application-air-for-android/' rel='bookmark' title='Permanent Link: Using Swipe Gestures in Mobile Flex Application (AIR for Android)'>Using Swipe Gestures in Mobile Flex Application (AIR for Android)</a></li>
<li><a href='http://www.flex-blog.com/flex-mobile-two-finger-tap-gesture-to-toggle-actionbar-visibility-in-a-view-air-for-android/' rel='bookmark' title='Permanent Link: Flex Mobile: Two finger tap gesture to toggle actionBar visibility in a View (AIR for Android)'>Flex Mobile: Two finger tap gesture to toggle actionBar visibility in a View (AIR for Android)</a></li>
<li><a href='http://www.flex-blog.com/view-navigation-in-a-mobile-flex-application/' rel='bookmark' title='Permanent Link: View Navigation in a Mobile Flex Application'>View Navigation in a Mobile Flex Application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="TweetButton_button" style="float: right; margin-left: 10px;;height:20px;margin-bottom:5px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.flex-blog.com%2Ftabbedmobileapplication-example-in-flex-mobile-air-for-android%2F&amp;text=TabbedMobileApplication Example in Flex Mobile (AIR for Android)&amp;count=vertical&amp;via=FlexBlog&amp;lang=en&amp;related=Flex+Mobile"><img src="http://www.flex-blog.com/wp-content/plugins/tweetbutton-for-wordpress/images/tweet.png" style="border:none" /></a></div>
<p><small style="visibility:hidden; font-size:1px;">Line Break</small>
<div class="atab_box">
<p><b>Author: <a href="http://www.flex-blog.com/author/admin/">Arjan</a></b> <small>(47 Articles)</small> - <a href="http://www.flex-blog.com">Author Website</a></p>
<img alt='' src='http://0.gravatar.com/avatar/29187d7302c1efbed2d457ec26cfbe4d?s=50&amp;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D50&amp;r=G' class='avatar avatar-50 photo' height='50' width='50' />
<p style="min-height:65px;">Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.</p>
</div><p><br />
So I&#8217;ve written a few post about mobile flex applications but all examples were based on a MobileApplication as a base for the application. Another option you have is a TabbedMobileApplication. This small example will show you how to use this to create your very own TabbedMobileApplication<br />
<span id="more-1389"></span><br />
Ok, first just create a Flex Mobile project in Flash Builder Burrito like always (I called it TabbedMobileApplicationExample). It can be based on MobileApplication. After that, change the TabbedMobileApplicationExample.mxml base tag to TabbedMobileApplication and remove the firstView property, a TabbedMobileApplication doesn&#8217;t have a firstView.</p>
<p>TabbedMobileApplicationExample.mxml:</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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:TabbedMobileApplication xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:TabbedMobileApplication<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Now lets define the tabs we want to use. Lets say the application should have the following tabs:</p>
<ul>
<li>Home</li>
<li>Details</li>
<li>Settings</li>
</ul>
<p>To get these tabs, we have to create three ViewNavigators inside our TabbedMobileApplication:</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 /></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: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:TabbedMobileApplication xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:ViewNavigator label=<span style="color: #ff0000;">&quot;Home&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;firstView=<span style="color: #ff0000;">&quot;views.Home&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:ViewNavigator label=<span style="color: #ff0000;">&quot;Details&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;firstView=<span style="color: #ff0000;">&quot;views.DetailsHome&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:ViewNavigator label=<span style="color: #ff0000;">&quot;Settings&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;firstView=<span style="color: #ff0000;">&quot;views.SettingsHome&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #66cc66;">&lt;/</span>s:TabbedMobileApplication<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>As you can see in the code, all ViewNavigators have a firstView property just like the MobileApplication does. Essentially, the MobileApplication is a ViewNavigator on its own. So now you basically have three navigators to worry about when you&#8217;re writing your application.</p>
<p>In my sample code I&#8217;m already pointing to views.Home, views.DetailsHome and views.SettingsHome. I renamed the already created view TabbedMobileApplicationExampleHome.mxml to Home.mxml and created to new views.</p>
<p>Also notice the label property on the ViewNavigators. This is the text that will be displayed on the tabs when you run your application.</p>
<p>So that&#8217;s it. Now you can work with tabs in your application. Navigation between views in every ViewNavigator works the same as explained in a <a href="http://www.flex-blog.com/view-navigation-in-a-mobile-flex-application/" target="_blank">previous post</a></p>


<p>Related posts:<ol><li><a href='http://www.flex-blog.com/using-swipe-gestures-in-mobile-flex-application-air-for-android/' rel='bookmark' title='Permanent Link: Using Swipe Gestures in Mobile Flex Application (AIR for Android)'>Using Swipe Gestures in Mobile Flex Application (AIR for Android)</a></li>
<li><a href='http://www.flex-blog.com/flex-mobile-two-finger-tap-gesture-to-toggle-actionbar-visibility-in-a-view-air-for-android/' rel='bookmark' title='Permanent Link: Flex Mobile: Two finger tap gesture to toggle actionBar visibility in a View (AIR for Android)'>Flex Mobile: Two finger tap gesture to toggle actionBar visibility in a View (AIR for Android)</a></li>
<li><a href='http://www.flex-blog.com/view-navigation-in-a-mobile-flex-application/' rel='bookmark' title='Permanent Link: View Navigation in a Mobile Flex Application'>View Navigation in a Mobile Flex Application</a></li>
</ol></p><img src="http://feeds.feedburner.com/~r/FlexBlog/~4/tD4lsdXHGv8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.flex-blog.com/tabbedmobileapplication-example-in-flex-mobile-air-for-android/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.flex-blog.com/tabbedmobileapplication-example-in-flex-mobile-air-for-android/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 1.488 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-05-16 03:46:03 --><!-- Compression = gzip -->

