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

<channel>
	<title>Interactive IQ : The Hessler Design Blog &#187; arrays</title>
	<atom:link href="http://www.hesslerdesign.com/blog/tag/arrays/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hesslerdesign.com/blog</link>
	<description>Smart Developers = Smart Websites</description>
	<lastBuildDate>Thu, 26 Jan 2012 23:00:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Formatting Raw Numbers with Commas</title>
		<link>http://www.hesslerdesign.com/blog/tutorials/formatting-raw-numbers-with-commas/</link>
		<comments>http://www.hesslerdesign.com/blog/tutorials/formatting-raw-numbers-with-commas/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 14:48:44 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=637</guid>
		<description><![CDATA[I&#8217;ve worked on a number of Flash projects where I&#8217;ve needed to convert a raw number into a correctly comma-formatted string for display.  Doing this is a relatively simple process, but since I found myself repeating the same chunk of code in multiple projects, I ended up creating a function that I could reuse over [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve worked on a number of Flash projects where I&#8217;ve needed to convert a raw number into a correctly comma-formatted string for display.  Doing this is a relatively simple process, but since I found myself repeating the same chunk of code in multiple projects, I ended up creating a function that I could reuse over and over again. And the nice thing about this chunk of code is that, with a few language-specific modifications, you can use it as JavaScript, PHP, etc.</p>
<p><code><span style="color: #999999;">// This variable gets set as 1,234,567,890</span><br />
<span style="color: #0000ff;">var</span> commaFormattedNumber:<span style="color: #0000ff;">String</span> = formatWithCommas(<span style="color: #009900;">"1234567890"</span>); </code></p>
<p><code><span style="color: #0000ff;">function</span> formatWithCommas(pNum_str:<span style="color: #0000ff;">String</span>):<span style="color: #0000ff;">String</span> {<br />
&nbsp; &nbsp;<span style="color: #0000ff;">var</span> lReturn_str:String = <span style="color: #009900;">""</span>;<br />
&nbsp; &nbsp;<span style="color: #0000ff;">var</span> lStringAsArray_arr:Array = pNum_str.split(<span style="color: #009900;">""</span>);<br />
&nbsp; &nbsp;<span style="color: #0000ff;">var</span> commaCounter_num:Number = 1;<br />
&nbsp; &nbsp;for (<span style="color: #0000ff;">var</span> i=lStringAsArray_arr.<span style="color: #0000ff;">length</span>-1; i&gt;=0; i--) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;lReturn_str = lStringAsArray_arr[i] + lReturn_str;<br />
&nbsp; &nbsp;&nbsp; &nbsp;<span style="color: #0000ff;">if</span> ((commaCounter_num == 3) &amp;&amp; (i != 0)) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;lReturn_str = "," + lReturn_str;<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;commaCounter_num = 1;<br />
&nbsp; &nbsp;&nbsp; &nbsp;} <span style="color: #0000ff;">else</span> {<br />
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;commaCounter_num++;<br />
&nbsp; &nbsp;&nbsp; &nbsp;}<br />
&nbsp; &nbsp;}<br />
&nbsp; &nbsp;<span style="color: #0000ff;">return</span> lReturn_str;<br />
}</code></p>
<h4>Notes:</h4>
<ul>
<li>In our example, we pass in 1 String value into the function, and it returns a String.</li>
<li>Inside of the function, we split the passed-in string into an Array, then we loop through the array backwards, adding the number in each array slot each time through the loop.</li>
<li>While looping through the array, notice that we have the variable <code>commaCounter_num</code>, which keeps track of which slots to also add in a comma. The conditional logic checks if the <code>commaCounter_num</code> is up to 3 and if the value of <code>i</code> is NOT zero. If both of these are true, we add in a comma and continue on. We must add the check of ensuring that <code>i</code> is not zero, so we don&#8217;t get a 6-digit number, for example, that ends up being returned with a comma at the very beginning of the string.</li>
</ul>
<p>So there you have it.  A nice little chunk of code you can use to format a number into a correctly comma-formatted string. Not a whole lot to it, but still a nice reference function to have for future use.</p>
<p>Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/tutorials/formatting-raw-numbers-with-commas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting Strings to Numbers in Adobe Flash</title>
		<link>http://www.hesslerdesign.com/blog/flash/converting-strings-to-numbers-in-adobe-flash/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/converting-strings-to-numbers-in-adobe-flash/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 14:47:26 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[Numbers]]></category>
		<category><![CDATA[Strings]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=610</guid>
		<description><![CDATA[I&#8217;ve had a few Flash projects I&#8217;ve worked on where I will find myself needing to import data from an external source, and I end up getting back String values that I will need to convert into Numbers.  While the actual process of converting a String to a Number is relatively simple (assuming your String [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a few Flash projects I&#8217;ve worked on where I will find myself needing to import data from an external source, and I end up getting back String values that I will need to convert into Numbers.  While the actual process of converting a String to a Number is relatively simple (assuming your String value is numeric, that is), I went one step further and came up with a script block that I can use to convert Strings to Numbers, even if I get a comma-delimited String of multiple numbers.  Here&#8217;s the code block, with an explanation of key items below.</p>
<p><code><span style="color: #0000ff;">var</span> sampleString_str:<span style="color: #0000ff;">String</span> = <span style="color: #009900;">"1, 23, 4, 5, 67"</span>;<br />
<span style="color: #0000ff;">var</span> convertedNumbers_arr:<span style="color: #0000ff;">Array</span> = <span style="color: #0000ff;">new Array</span>();<br />
<span style="color: #0000ff;">var</span> sampleStringAsArray_arr:<span style="color: #0000ff;">Array</span> = convertToArray(sampleString_str);<br />
convertArrayValuesToNumbers(sampleStringAsArray_arr);<br />
<span style="color: #0000ff;">function</span> convertToArray(pValue_str:<span style="color: #0000ff;">String</span>):Array {<br />
&nbsp; &nbsp;pValue_str = pValue_str.<span style="color: #0000ff;">replace</span>(<span style="color: #009900;">/ /</span>g, <span style="color: #009900;">""</span>);<br />
&nbsp; &nbsp;<span style="color: #0000ff;">var</span> lArray_arr:<span style="color: #0000ff;">Array</span> = pValue_str.<span style="color: #0000ff;">split</span>(<span style="color: #009900;">/,/</span>);<br />
&nbsp; &nbsp;<span style="color: #0000ff;">return</span> lArray_arr;<br />
}<br />
<span style="color: #0000ff;">function</span> getNumber(pValue_str:<span style="color: #0000ff;">String</span>):<span style="color: #0000ff;">Number</span> {<br />
&nbsp; &nbsp;<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">Number</span>(pValue_str);<br />
}<br />
<span style="color: #0000ff;">function</span> convertArrayValuesToNumbers(pArray_arr:<span style="color: #0000ff;">Array</span>):<span style="color: #0000ff;">void</span> {<br />
&nbsp; &nbsp;<span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i=0; i&lt;pArray_arr.<span style="color: #0000ff;">length</span>; i++) {<br />
&nbsp; &nbsp;&nbsp; &nbsp;convertedNumbers_arr[i] = getNumber(<span style="color: #0000ff;">String</span>(pArray_arr[i]));<br />
&nbsp; &nbsp;}<br />
}</code></p>
<h4>Notes:</h4>
<ul>
<li>In our example, the variable <code>sampleString_str</code> holds a sample String of comma-delimited number values. The empty array <code>convertedNumbers_arr</code> will hold each Number converted from sample String, once our functions start running. And the Array <code>sampleStringAsArray_arr</code> contains the individual String values of each item from <code>sampleString_str</code>.</li>
<li>In the function <code>convertToArray()</code>, we use <code>replace()</code> to clear out all spaces, if they exist, with the <code>g</code> (global) flag on regular expression so it will replace ALL, not just first instance of regular expression value. After space removal, we use the <code>split()</code> method to split the String into an Array at each instance of a comma. Once these run through, the function returns an Array, which we set equal to our variable <code>sampleStringAsArray_arr</code>.</li>
<li>In the function <code>convertArrayValuesToNumbers()</code>, we loop through the passed-in Array and assign each slot of <code>convertedNumbers_arr</code> to the Number value of the given array slot we are converting.</li>
<li>When all is said and done, the Array <code>convertedNumbers_arr</code> now holds actual Number values of each number from the original String, <code>sampleString_str</code>.</li>
</ul>
<p>Again, it doesn&#8217;t take much to convert a String to a Number, or even vice versa.  But with a few extra lines of code, we can take that to the next level and convert comma-delimited Strings to an Array of accompanying Number values that we can then use as true Numbers.</p>
<p>Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/converting-strings-to-numbers-in-adobe-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top Ten Ways to Optimize Your Flash Website</title>
		<link>http://www.hesslerdesign.com/blog/flash/top-ten-ways-to-optimize-your-flash-website/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/top-ten-ways-to-optimize-your-flash-website/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 17:45:12 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=324</guid>
		<description><![CDATA[Let&#8217;s face it.  When it comes to Flash websites, people either love them or hate them.  For those who hate them, I firmly believe it&#8217;s because of two main reasons: crappy SEO (search engine optimization), and long load times (a direct result of heavy file weights).  While the issue of SEO is its own beast, [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s face it.  When it comes to Flash websites, people either love them or hate them.  For those who hate them, I firmly believe it&#8217;s because of two main reasons: crappy SEO (search engine optimization), and long load times (a direct result of heavy file weights).  While the issue of SEO is its own beast, I won&#8217;t get into that now.  For now, I&#8217;m going to focus on 10 easy ways to optimize your Flash website to make it meaner, leaner, and more user-friendly.  Believe me, if you start using some of these ideas, your sites will transform in ways you never though imaginable.  And you&#8217;ll notice that you&#8217;ll get a much smoother and quicker site.  With that said, let&#8217;s get started.</p>
<h4>1. Use XML files to set content framework</h4>
<p>On nearly every Flash site I work on, I use at least some XML. The great thing about XML files is they are a great way to structure blocks of your site.  For instance, if you want a slideshow on your site, you could have an XML file that contains the title, url, and other image-specific information you want to include for each image. Then, just import the XML into Flash and store the XML data in arrays to organize the information to use later.  (More on arrays below.)</p>
<p>Another great thing about using XML in Flash is that if you want to stream an RSS feed into a Flash site, you can, because RSS feeds are set up as XML.  (For more info on RSS feeds, see the post on <a href="http://www.hesslerdesign.com/blog/flash-actionscript/streaming-rss-feeds-into-your-flash-application/" target="_self">Streaming RSS feeds into Your Flash Applications</a>.)</p>
<p>Additionally, XML is easy to change without having to republish your site.  Say you have that slideshow I mentioned above, but want to swap out an image.  With XML, you just point to the new url, update the title, and save. Your Flash site will automatically update with the new info, and you won&#8217;t have to republish every time. Trust me, you&#8217;ll thank yourself for using XML when you build your Flash site.</p>
<h4>2. Use arrays to organize assets used in your code</h4>
<p>For me, using arrays is quite possibly one of the smartest and most powerful things you can do to optimize your code.  Not necessarily from a file weight perspective, but because with arrays, you can reference an object stored in an array by name, number, id, etc. For instance, say you have 20 thumbnail images you want to make clickable to open a larger image. You could attach individual event listeners to each image.  Or, you could set up a couple of arrays &#8212; one for the instance names of each image, and one for the reference to the larger image to load when clicked &#8212; and run &#8220;for&#8221; loops to set the event listeners all at once. While you&#8217;re in the &#8220;for&#8221; loop, set an ID number for each image that you can then reference in your &#8220;click&#8221; function that will fire on mouse click, and call up that ID number slot in the large image array.  With only a few lines of code, you&#8217;ll have a powerful way to batch chunks of your code with minimal effort. (For more info on arrays, see my post on <a href="http://www.hesslerdesign.com/blog/flash-actionscript/utilizing-the-power-of-arrays-in-adobe-flash/" target="_self">Utilizing the Power of Arrays in Adobe Flash</a>.)</p>
<h4>3. Only import and embed absolutely necessary image files into your file.</h4>
<p>If you&#8217;ve been on the Web at all&#8230;and judging by you reading this, I&#8217;m guessing you have&#8230;you know doubt know that a lot of people don&#8217;t like Flash sites.  The main reason seems to be they take way too long to load.  To get around this, I highly suggest importing and embedding ONLY the images you absolutely need.  If you have a lot of image assets, I suggest loading them dynamically via code, and placing them in the appropriate places.  This not only makes the file size considerably smaller, but it also opens the door to be able to update an image, replace it, and have Flash automatically read in the updated file without the need to republish the entire site.  (Sorta sounds like one of the key perks of using XML, doesn&#8217;t it?)  And trust me, users will thank you for having a site that loads (or at least shows up with a short preloader) in 5 seconds, rather than a beefy site that doesn&#8217;t show up until the entire thing loads.</p>
<h4>4. Load assets in an orderly fashion, not all at once</h4>
<p>Along with #3 above, when you load assets into your Flash site dynamically, it&#8217;s best to set up a structure and order in which to load them. For instance, load all of the home/landing page assets first. Once those are loaded, proceed with the next set of assets that you think will be needed/viewed by your users.  Not using a certain set of images until later in the site?  Don&#8217;t load them up front. Wait until the rest of the assets before it have been loaded first. Think about it.  Would you rather try to have 20 images load all at once?  Or load them in the order of which they&#8217;ll be seen? Loading them one at a time will speed up the individual image load time because there is only one image needing attention while it is being loaded, not all 20?</p>
<h4>5. Cool it with the videos</h4>
<p>Okay, this sounds harsh, but hear me out. Video is great. It&#8217;s everywhere, and it&#8217;s getting more popular by the day.  (YouTube, anyone?)  But when you&#8217;re making a Flash site, video can also be a beast to work with, specifically video that needs to stream without a playback bar.  The worst thing about video is file size. I&#8217;ll admit, video has come a long way in optimizing file weights and all, but at the end of the day, even a small video is still going to be around 1-2MB.  When you are using video, make sure you utilize the &#8220;loading assets in an orderly fashion&#8221; advice from above.  If you try to start streaming a video when 20 images are loading while it&#8217;s trying to play, you&#8217;ll no doubt get choppy playback.</p>
<h4>6. Use TweenMax or TweenLite for code-based tweening and animating</h4>
<p>I&#8217;m a big fan of keeping my Flash sites on one frame of the timeline, and doing as much as I possibly can with code, rather than with the timeline.  The reason for this is simply less time making changes later on down the road.  Want to make every tween of an image fading out half as long across the entire site?  Pretty laborious if you&#8217;re using the timeline.  But if you&#8217;re using code, it&#8217;s a matter of updating a couple of numbers.</p>
<p>This is where <a href="http://blog.greensock.com/tweenmax/" target="_blank">TweenMax</a> and <a href="http://blog.greensock.com/tweenlite/" target="_blank">TweenLite</a> come in.  In a nutshell, they&#8217;re the best tweening engine out there.  Using it, you can call one function that can alter many facets of an object at once (x and y position, alpha, tint, etc.).  You can also attach event listeners like onComplete, onStart, etc., that call functions to run at specific times during the tween.  In short, these tweening engines will make you wonder why you ever used timeline-based animations.  And best of all, they&#8217;re extremely light in file weight, unlike a lot of timeline-based animations.  And it&#8217;s a one-time file weight addition, not a per-tween sort of thing.</p>
<h4>7. Simulate downloading on slower connections</h4>
<p>Not everyone has a cable-speed connection. Believe it or not, there are still a lot of people out there using DSL or slower connections.  And as unfortunate as it may be, those are the people you need to build the site for.  Don&#8217;t ever assume that your audience is going to have the latest and greatest computers.</p>
<p>To simulate downloads in Flash, export your movie and select &#8220;View &gt; Simulate Download&#8221;.  To set different connection speed settings, select &#8220;View &gt; Download Settings&#8221;, and select your desired speed (or create your own custom speed).  Flash can be deceiving. When you test out a movie, it always runs lightning fast. But by testing it using the &#8220;Simulate Download&#8221; method, you&#8217;ll get a much better idea of how your site will behave on the Web.</p>
<h4>8. Build buttons and other UI components as vector artwork in Flash</h4>
<p>One of my biggest pet peeves is using raster images for buttons that could easily be made as vector art in Flash.  Not only does this make having to update the button a multi-step process, but it also beefs up the size of the file.  It may not be much, but if you get a dozen different image buttons, you could easily have just added 100+ kb to your file weight.  Might not seem by much, but as people&#8217;s attention spans are getting shorter and shorter, that added 2 seconds of load time you just added might be costly, and you may see an increase in the number of dropped users.</p>
<p>My motto is this: &#8220;<em>If it can be made in Flash, make it in Flash&#8221;</em>.  Vector art is not only easily editable, but also a huge file weight saver.  Plus, you don&#8217;t get any degradation of quality that you&#8217;d get if you used images.  All of your lines, colors, gradients, etc. are crystal clear.  Pair that with the almost non-existent file weight they carry, and what&#8217;s not to love?</p>
<h4>9. Write custom Classes for reusable code</h4>
<p>If you write Actionscript code, you use Classes.  You might not know it, but you do.  Every time you use a property of a MovieClip instance (i.e. myClip_mc.y to get the &#8220;y&#8221; position), you&#8217;re calling the MovieClip class.  Same with Sprites, Buttons, UI Components, etc.  Classes are a staple in object-oriented programming, and allow you to read or set properties, call functions (methods), and respond to events.  It&#8217;s a great way to reuse the same code over and over again, by simply importing the classes into your site file.</p>
<p>One of my personal favorite classes that I have written is for an Email Validator, which contains the logic to check whether a string is a valid email address or not.  You can check it out in my previous post on <a href="http://www.hesslerdesign.com/blog/flash-actionscript/building-a-better-email-validator-in-flash/" target="_self">Building a Better Email Validator in Flash</a>.  Each time I need to use this, I simply import it into my file (which is 1 line of code), make an instance of the validator (1 line of code), then call the validate function and pass in the string to validate (1 line of code).  In all, for me to validate an email address, it takes 3 lines of code.  Much better than rewriting all of the validation logic in a dozen different files, eh?</p>
<h4>10. Use FlashVars to set important global variables</h4>
<p>Every so often, you&#8217;ll run into an issue where you&#8217;ll want to change a variable from outside of your Flash file. An easy way to do this is to use the FlashVars parameter when embedding your Flash file in HTML.  I find that I mostly use FlashVars for variables that will change from a &#8220;staging&#8221; site to the final &#8220;production&#8221; site.  The most often used variable that I personally encounter is the account name for Omniture tracking. The bulk of sites I develop have different staging and production Omniture account names, so the metrics don&#8217;t get skewed while testing.  But if I embed that account name into the Flash file, I suddenly need 2 different versions of the Flash file &#8212; one for staging, one for production.  But if I have a FlashVar set up for this account name, I can just change the variable in the HTML code, and have Flash read it in.  Trust me, it&#8217;s a handy way to avoid having multiple versions of the same file for different environments.</p>
<h4>In Conclusion&#8230;</h4>
<p>So there you have it.  10 easy ways to optimize your Flash sites.  There are many more ways to optimize Flash sites, and I&#8217;m sure I&#8217;ll get into them in later posts.  But these are some of the main culprits.  And trust me, individual posts could be written about each one of these (and some already have).  If you want to see posts that dive deeper into any of these, just let me know and I&#8217;ll write it up.  Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/top-ten-ways-to-optimize-your-flash-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Streaming RSS Feeds into Your Flash Application</title>
		<link>http://www.hesslerdesign.com/blog/flash/streaming-rss-feeds-into-your-flash-application/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/streaming-rss-feeds-into-your-flash-application/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 21:30:35 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=300</guid>
		<description><![CDATA[One of the great things about RSS feeds is that RSS formats are specified using XML.  Because of this, you can parse the RSS feed in your Flash applications just as you would an XML file.  So if, for instance, you have a Flash-based website that you would like to add a &#8220;Recent Blog Posts&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great things about RSS feeds is that RSS formats are specified using XML.  Because of this, you can parse the RSS feed in your Flash applications just as you would an XML file.  So if, for instance, you have a Flash-based website that you would like to add a &#8220;Recent Blog Posts&#8221; section to, you can just import the RSS into Flash and *BAM*, you&#8217;re all set.  Here&#8217;s a quick rundown of how to do it:</p>
<h4>Step 1: Locate the RSS Feed</h4>
<p>If you&#8217;re the owner of a blog that you want to get the RSS feed to, all you should need to do is go to the blog&#8217;s home page, and add &#8220;/feed/&#8221; to the end of the URL.  (For example: <a title="Hessler Design Blog Feed" href="http://www.hesslerdesign.com/blog/feed/" target="_blank">http://www.hesslerdesign.com/blog/feed/</a>)  This is an XML-based page that gives you a list of the blog&#8217;s posts, titles, contents/extracts, etc.</p>
<p>If you need an RSS feed through a service like FeedBurner, you first need to go to the FeedBurner page of the site you want an RSS feed from. (For example: <a title="Hessler Design Blog Feed" href="http://feeds.feedburner.com/hesslerdesign" target="_blank">http://feeds.feedburner.com/hesslerdesign</a>)  This page is NOT the one you need to link to, however.  At this page you&#8217;ll notice a link to &#8220;View Feed XML&#8221; in the Subscribe Now! box.  Click on that link, and you&#8217;ll be presented with a page exactly like that of the &#8220;/feed/&#8221; URL mentioned in the previous paragraph.</p>
<p>Once you get to the XML-based page, copy the URL, because you&#8217;ll need it in Flash.  (If you want to confirm that the page is the correct one, view the page&#8217;s source. It will be set up as an XML file, with a line like <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code> at the very top.)</p>
<h4>Step 2: Importing the RSS Feed into Flash</h4>
<p>To import the feed into Flash, just follow the normal steps you would to import an XML file.  Create an <code>XML</code> object and a <code>URLLoader</code> object, then load your RSS feed URL using the <code>URLLoader</code>.  Since I&#8217;m the type of developer who likes to code as dynamically and flexibly as possible, I like to also set up an empty array for each of the items I want to hold from the RSS feed, such as titles and permalinks.  Then, when I parse the XML, I assign a slot in the appropriate array for each title and accompanying permalink, and then have them to use when I display the Recent Posts section.  Here&#8217;s how to do this:</p>
<div style="margin-left: 24px;"><code><span style="color: #808080;">/* Begin ActionScript 3.0 Code */</span><br />
<span style="color: #0000ff;">var</span> rssXML:<span style="color: #0000ff;">XML</span>;<br />
<span style="color: #0000ff;">var</span> rssLoader:<span style="color: #0000ff;">URLLoader</span>;<br />
<span style="color: #0000ff;">var</span> rssTitles_arr:<span style="color: #0000ff;">Array</span> = <span style="color: #0000ff;">new Array</span>();<br />
<span style="color: #0000ff;">var</span> rssLinks_arr:<span style="color: #0000ff;">Array</span> = <span style="color: #0000ff;">new Array</span>();<br />
<span style="color: #0000ff;">function</span> importFeed():<span style="color: #0000ff;">void</span> {<br />
rssLoader = <span style="color: #0000ff;">new URLLoader</span>();<br />
rssLoader.<span style="color: #0000ff;">addEventListener</span>(<span style="color: #0000ff;">Event.COMPLETE</span>, loadRSS);<br />
rssLoader.<span style="color: #0000ff;">load</span>(<span style="color: #0000ff;">new URLRequest</span>(<span style="color: #009900;">"http://www.hesslerdesign.com/blog/feed/"</span>));<br />
}<br />
<span style="color: #0000ff;">function</span> loadRSS(e:<span style="color: #0000ff;">Event</span>):void {<br />
rssXML = <span style="color: #0000ff;">new XML</span>(e.<span style="color: #0000ff;">target.data</span>);<br />
<span style="color: #0000ff;">trace</span>(rssXML);<br />
<span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i=0; i&lt;4; i++) {<br />
rssTitles_arr[i] = rssXML.channel.item[i].title;<br />
rssLinks_arr[i] = rssXML.channel.item[i].link;<br />
}<br />
<span style="color: #808080;">// Garbage Collection</span><br />
rssLoader.<span style="color: #0000ff;">removeEventListener</span>(<span style="color: #0000ff;">Event.COMPLETE</span>, loadRSS);<br />
}<br />
importFeed();<br />
<span style="color: #808080;">/* End ActionScript 3.0 Code */</span></code></div>
<h4>An important note:</h4>
<p>To dig down into the XML and get things like Post titles and permalinks, you need to be familiar with the structure of the RSS file.  You can see from the code above that the title for each post is inside an item tag, which sits inside of the channel tag.  If you want to get more info than just these two items, just go to the RSS URL (see Step 1) and view the page source.  Or, you can do as I&#8217;ve done in the code above and trace out the XML in Flash once the XML loads.  This is a helpful first step to see what the structure of the XML file is before you get into parsing the XML into appropriate arrays.</p>
<p>Another quick thing to note is in the <code>for</code> loop, inside of the <code>loadRSS()</code> function.  I used the number 4 as a benchmark to populate my arrays (seen in the snippet <code>i&lt;4</code>).  You can use a different number if you want.  It&#8217;s a matter of (a) the number of posts available in the RSS feed, and (b) personal preference.</p>
<p>Once you incorporate the code above, you can then use the arrays populated with RSS info and populate text fields, buttons, etc.  Since it&#8217;s stored in an array, the possibilities are virtually limitless.</p>
<p>So there you have it.  The flexibility of RSS feeds makes it just that easy to import into Flash.  Until next time, happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/streaming-rss-feeds-into-your-flash-application/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Utilizing the Power of Arrays in Adobe Flash</title>
		<link>http://www.hesslerdesign.com/blog/flash/utilizing-the-power-of-arrays-in-adobe-flash/</link>
		<comments>http://www.hesslerdesign.com/blog/flash/utilizing-the-power-of-arrays-in-adobe-flash/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 19:30:12 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[arrays]]></category>

		<guid isPermaLink="false">http://www.hesslerdesign.com/blog/?p=29</guid>
		<description><![CDATA[Each time I program a project in Adobe Flash using ActionScript, I try to keep the code as concise as possible—partly because it helps in processing the code, and partly because I’m a nut for clean code that’s easy to update on the fly with minimal effort. In ActionScript 3.0, I am continually finding myself [...]]]></description>
			<content:encoded><![CDATA[<p>Each time I program a project in Adobe Flash using ActionScript, I try to keep the code as concise as possible—partly because it helps in processing the code, and partly because I’m a nut for clean code that’s easy to update on the fly with minimal effort.  In ActionScript 3.0, I am continually finding myself coming up with new ways to clean up my code and keep it as lean as possible.  One way I do this is through the use of Arrays.</p>
<p>Now Arrays are nothing new to any programmer out there, but I find that in ActionScript 3.0, I’m using them much more so than I ever did in ActionScript 2.0.  The main reason for this is that I like to use the same set of functions for button actions over a range of similar buttons.  Since ActionScript 3.0 requires you to pass a function into each listener event for every button, I like to use Arrays to sort my buttons and accompanying objects, and thereby creating the chance to use the same function for all buttons.<span id="more-29"></span></p>
<p>The sample Flash movie below shows this in action.  I created a very simple 4-section flipbook, and have used the same function for all Mouse Click events.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="200" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/06/flipbook_arrays.swf" /><embed type="application/x-shockwave-flash" width="550" height="200" src="http://www.hesslerdesign.com/blog/wp-content/uploads/2009/06/flipbook_arrays.swf"></embed></object></p>
<p><a href="../../wp-content/uploads/2009/06/Array-Flipbook.zip">Download Flash Source Files »</a></p>
<p>Here&#8217;s the code used for this movie.  Note how concise the code is, thanks to the use of my two main arrays.</p>
<p><code><span style="color: #999999;">/* — Begin Code — */</span></code></p>
<p><code><span style="color: #0000ff;">var</span> links:<span style="color: #0000ff;">Array</span> = [link0_mc, link1_mc, link2_mc, link3_mc];</code><br />
<code><span style="color: #0000ff;">var</span> pages:<span style="color: #0000ff;">Array</span> = [page0_mc, page1_mc, page2_mc, page3_mc];</code></p>
<p><code><span style="color: #0000ff;">function</span> setLinks():<span style="color: #0000ff;">void</span> {</code><br />
<code>&nbsp; &nbsp;<span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i:<span style="color: #0000ff;">int</span>=0; i&lt;links.<span style="color: #0000ff;">length</span>; i++) {</code><br />
<code>&nbsp; &nbsp;&nbsp; &nbsp;links[i].<span style="color: #0000ff;">id</span> = i;</code><br />
<code>&nbsp; &nbsp;&nbsp; &nbsp;links[i].<span style="color: #0000ff;">buttonMode</span> = true;</code><br />
<code>&nbsp; &nbsp;&nbsp; &nbsp;links[i].<span style="color: #0000ff;">addEventListener</span>(<span style="color: #0000ff;">MouseEvent.CLICK</span>, linkClick);</code><br />
<code>&nbsp; &nbsp;}</code><br />
<code>}</code></p>
<p><code><span style="color: #0000ff;">function</span> linkClick(e:<span style="color: #0000ff;">MouseEvent</span>):<span style="color: #0000ff;">void</span> {</code><br />
<code>&nbsp; &nbsp;hideAllPages();</code><br />
<code>&nbsp; &nbsp;showPage(e.<span style="color: #0000ff;">currentTarget</span>.<span style="color: #0000ff;">id</span>);</code><br />
<code>}</code></p>
<p><code><span style="color: #0000ff;">function</span> hideAllPages():<span style="color: #0000ff;">void</span> {</code><br />
<code>&nbsp; &nbsp;<span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">var</span> i:<span style="color: #0000ff;">int</span>=0; i&lt;pages.<span style="color: #0000ff;">length</span>; i++) {</code><br />
<code>&nbsp; &nbsp;&nbsp; &nbsp;pages[i].<span style="color: #0000ff;">visible</span> = <span style="color: #0000ff;">false</span>;</code><br />
<code>&nbsp; &nbsp;}</code><br />
<code>}</code></p>
<p><code><span style="color: #0000ff;">function</span> showPage(pageNum:<span style="color: #0000ff;">Number</span>):<span style="color: #0000ff;">void</span> {</code><br />
<code>&nbsp; &nbsp;pages[pageNum].<span style="color: #0000ff;">visible</span> = <span style="color: #0000ff;">true</span>;</code><br />
<code>}</code></p>
<p><code>hideAllPages();</code><br />
<code>showPage(0);</code><br />
<code>setLinks();</code></p>
<p><code><span style="color: #999999;">/* — End Code — */</span></code></p>
<p><span style="color: #999999;"><span style="color: #000000;">In this Flash movie, the links and pages are named with the same numerical value (i.e. <code>link0_mc</code> corresponds to <code>page0_mc</code>).  They also share the same place in their respective arrays, creating the ability to utilize loops in the <code>linkClick</code> and <code>hideAllPages</code> functions.</span></span></p>
<p><span style="color: #999999;"><span style="color: #000000;">Of course this is just a simple example, but with a little extra effort, the same concept can easily be used for more complex applications.  Happy coding!</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hesslerdesign.com/blog/flash/utilizing-the-power-of-arrays-in-adobe-flash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

