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

<channel>
	<title>Flex Insights</title>
	<atom:link href="http://hozdemir.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hozdemir.wordpress.com</link>
	<description>Insights into Flex: exhaustive but not exhausting...</description>
	<lastBuildDate>Mon, 04 May 2009 16:58:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='hozdemir.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Flex Insights</title>
		<link>http://hozdemir.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://hozdemir.wordpress.com/osd.xml" title="Flex Insights" />
	<atom:link rel='hub' href='http://hozdemir.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Enumerations With Class</title>
		<link>http://hozdemir.wordpress.com/2009/05/03/enumerations-with-class/</link>
		<comments>http://hozdemir.wordpress.com/2009/05/03/enumerations-with-class/#comments</comments>
		<pubDate>Sun, 03 May 2009 03:03:48 +0000</pubDate>
		<dc:creator>hozdemir</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hozdemir.wordpress.com/2009/05/03/enumerations-with-class/</guid>
		<description><![CDATA[  References: Prog  ActionScript 3.0 – Enumerations with Classes: http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&#38;file=04_OO_Programming_161_07.html http://www.herrodius.com/blog/87 http://www.barneyb.com/barneyblog/2007/11/02/enums-and-actionscripts-static-initializers/ Environment: ActionScript 3.0; Flex Builder 3.0 with Flex SDK 3.2 Keywords: ActionScript 3.0,  Enumerations with Classes, private constructor, singleton, static code block Enumerations: ActionScript  3.0 documents suggest the use of  classes with only static constants as a way to create enumerations. The first [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hozdemir.wordpress.com&amp;blog=7438567&amp;post=39&amp;subd=hozdemir&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>References:<br />
Prog  ActionScript 3.0 – Enumerations with Classes:<br />
<a href="http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=04_OO_Programming_161_07.html">http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=04_OO_Programming_161_07.html</a></p>
<p><a href="http://www.herrodius.com/blog/87">http://www.herrodius.com/blog/87</a></p>
<p><a href="http://www.barneyb.com/barneyblog/2007/11/02/enums-and-actionscripts-static-initializers/">http://www.barneyb.com/barneyblog/2007/11/02/enums-and-actionscripts-static-initializers/</a></p>
<p>Environment:<br />
ActionScript 3.0; Flex Builder 3.0 with Flex SDK 3.2</p>
<p>Keywords:<br />
ActionScript 3.0,  Enumerations with Classes, private constructor, singleton, static code block</p>
<h4>Enumerations:</h4>
<p>ActionScript  3.0 documents suggest the use of  classes with only static constants as a way to create enumerations.</p>
<p>The first approach uses variables of basic types such as String, int, or uint within a class.  In fact, Flash API use this approach, as in the following code, we are told:</p>
<pre>public final class PrintJobOrientation
{
    public static const LANDSCAPE:String = "landscape";
    public static const PORTRAIT:String = "portrait";
}</pre>
<p>The  second approach involves a separate class with static properties for the enumeration:  Here, each static property is an instance of the class and thus allows improved type checking. The example provided is as follows:</p>
<pre>public final class Day
{
    public static const MONDAY:Day = new Day();
    public static const TUESDAY:Day = new Day();
    public static const WEDNESDAY:Day = new Day();
    public static const THURSDAY:Day = new Day();
    public static const FRIDAY:Day = new Day();
    public static const SATURDAY:Day = new Day();
    public static const SUNDAY:Day = new Day();
}</pre>
<p>An example usage is as follows:</p>
<pre>function getDay():Day
{
    var date:Date = new Date();
    var retDay:Day;
    switch (date.day)
    {
        case 0:
            retDay = Day.MONDAY;
            break;
        case 1:
            retDay = Day.TUESDAY;
            break;
        case 2:
            retDay = Day.WEDNESDAY;
            break;
        case 3:
            retDay = Day.THURSDAY;
            break;
        case 4:
            retDay = Day.FRIDAY;
            break;
        case 5:
            retDay = Day.SATURDAY;
            break;
        case 6:
            retDay = Day.SUNDAY;
            break;
    }
    return retDay;
}</pre>
<p>Note that the return type is Day; this is how enhanced type checking comes into play.</p>
<h4>Exercise for the Reader: Enhancing the Day Class Sample</h4>
<p>Adobe documentation suggests an exercise for the reader: enhance this class by associating an integer with each day, as well as a string representation. Here is my solution:</p>
<pre>package
{
    public class MyDay
    {
        private var _dayNum:int;
        private var _dayStr:Array = ["Sun","Mon","Tues","Wednes","Thus","Fri","Satur"];

        public static const SUNDAY:MyDay    = new MyDay(0);
        public static const MONDAY:MyDay    = new MyDay(1);
        public static const TUESDAY:MyDay   = new MyDay(2);
        public static const WEDNESDAY:MyDay = new MyDay(3);
        public static const THURSDAY:MyDay  = new MyDay(4);
        public static const FRIDAY:MyDay    = new MyDay(5);
        public static const SATURDAY:MyDay  = new MyDay(6);
        public function MyDay(dayNum:int)
        {
            _dayNum=dayNum;
        }
        public function get dayNum():int
        {
            return _dayNum;
        }
        public function get dayStr():String
        {
            return _dayStr[_dayNum]+”day”;;
        }
        public function toString():String
        {
            return dayStr;
        }
    }
}
class SingletonEnforcer {}</pre>
<p>I had intended to use class  SingletonEnforcer to restrict the use of  MyDay constructor to this package,  since I cannot make the MyDay constructor private; but that leads to TypeError 1115. According to <a href="http://www.herrodius.com/blog/87">http://www.herrodius.com/blog/87</a> , it is impossible to call the constructor of the inner class (i.e. SingletonEnforcer) in a static member of the top class. </p>
<p>The alternative is to use an unnamed  static code block:</p>
<pre>private static var _enumsInited:Boolean = false;
//unnamed static code block
{
    _ enumsInited = true;
}</pre>
<p>and  then modify the constructor; the final code is as follows:</p>
<pre>package
{
    public class MyDay
    {
        private var _dayNum:int;
        private var _dayStr:Array = ["Sun","Mon","Tues","Wednes","Thus","Fri","Satur"];

        public static const SUNDAY:MyDay    = new MyDay(0);
        public static const MONDAY:MyDay    = new MyDay(1);
        public static const TUESDAY:MyDay   = new MyDay(2);
        public static const WEDNESDAY:MyDay = new MyDay(3);
        public static const THURSDAY:MyDay  = new MyDay(4);
        public static const FRIDAY:MyDay    = new MyDay(5);
        public static const SATURDAY:MyDay  = new MyDay(6);
        private static var _enumsInited:Boolean = false;
        //unnamed static code block
        {
            _enumsInited = true;
        }
        public function MyDay(dayNum:int)
        {
            if (_enumsInited)
                throw new Error("[MyDay] The enum is already inited.");

            _dayNum=dayNum;
        }
        public function get dayNum():int
        {
            return _dayNum;
        }
        public function get dayStr():String
        {
            return _dayStr[_dayNum]+”day”;
        }
        public function toString():String
        {
            return dayStr;
        }
    }
}</pre>
<p>This works, because the static code is executed after all static members have been set!</p>
<p>From<br />
<a href="http://www.barneyb.com/barneyblog/2007/11/02/enums-and-actionscripts-static-initializers/">http://www.barneyb.com/barneyblog/2007/11/02/enums-and-actionscripts-static-initializers/</a></p>
<p>In a nutshell, a static initializer is kind of like a constructor, but it&#8217;s for the class object itself, not instances of the class. It gets invoked during classloading, after all static properties have been set, but the class is turned loose for general consumption.</p>
<p>Here is the code where I exercised the above classes Day and MyDay:</p>
<pre>package {
    import flash.display.Sprite;

    public class EnumClassAS3 extends Sprite
    {
        public function EnumClassAS3()
        {
            var dayOfWeek:Day = getDay();
            trace (dayOfWeek);
            //Today is (was) Saturday:
            if (dayOfWeek == Day.SATURDAY) {
                trace("[Day] SATURDAY");
            }
            else {
                trace("[Day] Not SATURDAY");
            }
            var strDay:String;
            switch (dayOfWeek)
            {
                case Day.SATURDAY:
                    strDay="Saturday"
                    break;
                default:
                    strDay="Not Saturday";
                    break;
            }
            trace("[Day] strDay:" + strDay);
            var myDay:MyDay = getMyDay();
            trace("[MyDay] dayNum:"+ myDay.dayNum );
            trace("[MyDay] toString:"+myDay);
            trace("[MyDay] dayStr:"+ myDay.dayStr );
            if (myDay == MyDay.SATURDAY) {
                trace("MyDay is: " +"SATURDAY");
            }
            else {
                trace("MyDay is NOT: " +"SATURDAY");
            }
            var myOtherDay=getMyDay();
            if (myOtherDay == MyDay.SATURDAY)
                trace("MyOtherDay is: " +"SATURDAY");
            if (myOtherDay == myDay)
                trace ("SameDay");
            if (myOtherDay === myDay)
                trace ("SameStrictDay");
            var extraDay:MyDay=new MyDay(8);
        }
        private function getDay():Day
        {
            var date:Date = new Date();
            var retDay:Day;
            switch (date.day)
            {
                case 0:
                    retDay = Day.SUNDAY;
                    break;
                case 1:
                    retDay = Day.MONDAY;
                    break;
                case 2:
                    retDay = Day.TUESDAY;
                    break;
                case 3:
                    retDay = Day.WEDNESDAY;
                    break;
                case 4:
                    retDay = Day.THURSDAY;
                    break;
                case 5:
                    retDay = Day.FRIDAY;
                    break;
                case 6:
                    retDay = Day.SATURDAY;
                    break;
            }
            return retDay;
        }
        private function getMyDay():MyDay
        {
            var date:Date = new Date();
            var retDay:MyDay;
            switch (date.day)
            {
                case 0:
                    retDay = MyDay.SUNDAY;
                    break;
                case 1:
                    retDay = MyDay.MONDAY;
                    break;
                case 2:
                    retDay = MyDay.TUESDAY;
                    break;
                case 3:
                    retDay = MyDay.WEDNESDAY;
                    break;
                case 4:
                    retDay = MyDay.THURSDAY;
                    break;
                case 5:
                    retDay = MyDay.FRIDAY;
                    break;
                case 6:
                    retDay = MyDay.SATURDAY;
                    break;
            }
            return retDay;
        }
    }
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hozdemir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hozdemir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hozdemir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hozdemir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hozdemir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hozdemir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hozdemir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hozdemir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hozdemir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hozdemir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hozdemir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hozdemir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hozdemir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hozdemir.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hozdemir.wordpress.com&amp;blog=7438567&amp;post=39&amp;subd=hozdemir&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hozdemir.wordpress.com/2009/05/03/enumerations-with-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab4a8b1537fd5d63112d5807b331f29f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hozdemir</media:title>
		</media:content>
	</item>
		<item>
		<title>Flex Builder 3 Tips</title>
		<link>http://hozdemir.wordpress.com/2009/04/28/flex-builder-3-tips/</link>
		<comments>http://hozdemir.wordpress.com/2009/04/28/flex-builder-3-tips/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 21:56:30 +0000</pubDate>
		<dc:creator>hozdemir</dc:creator>
				<category><![CDATA[Flex Builder 3]]></category>

		<guid isPermaLink="false">http://hozdemir.wordpress.com/2009/04/28/flex-builder-3-tips/</guid>
		<description><![CDATA[  Debugging: Using Standalone Flash Player Are you tired of waiting for the browser to launch after starting your debugging session? Then, you should use the debug version of the standalone Flash Player. To do so: right click on your project in the Flex Navigator, select “Properties” and in the resulting dialog (see below), choose [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hozdemir.wordpress.com&amp;blog=7438567&amp;post=28&amp;subd=hozdemir&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> </p>
<h4>Debugging: Using Standalone Flash Player</h4>
<p>Are you tired of waiting for the browser to launch after starting your debugging session? Then, you should use the debug version of the standalone Flash Player. To do so:</p>
<ul>
<li>right click on your project in the Flex Navigator,</li>
<li>select “Properties” and in the resulting dialog (see below),</li>
<li>choose the “ActionScript Compiler” entry on the left sidebar,</li>
<li>uncheck :Generate HTML wrapper file.</li>
</ul>
<p>You are now set to use the standalone Flash Player. If you do not have the debug version of the Flash Player, which is required for this option, Flex Builder will inform you.</p>
<p>Adobe sites have tools to tell you what version of Flash Player you have and the debug standalone player as well.</p>
<p>You can go back to using the browser by checking “Generate HTML wrapper file.”</p>
<p><a href="http://hozdemir.files.wordpress.com/2009/04/htmlwrapper.jpg"><img style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" title="HTMLWrapper" src="http://hozdemir.files.wordpress.com/2009/04/htmlwrapper-thumb.jpg?w=450&#038;h=360" border="0" alt="HTMLWrapper" width="450" height="360" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hozdemir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hozdemir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hozdemir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hozdemir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hozdemir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hozdemir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hozdemir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hozdemir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hozdemir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hozdemir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hozdemir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hozdemir.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hozdemir.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hozdemir.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hozdemir.wordpress.com&amp;blog=7438567&amp;post=28&amp;subd=hozdemir&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hozdemir.wordpress.com/2009/04/28/flex-builder-3-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab4a8b1537fd5d63112d5807b331f29f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hozdemir</media:title>
		</media:content>

		<media:content url="http://hozdemir.files.wordpress.com/2009/04/htmlwrapper-thumb.jpg" medium="image">
			<media:title type="html">HTMLWrapper</media:title>
		</media:content>
	</item>
		<item>
		<title>Insight into AS3 Indexed Arrays</title>
		<link>http://hozdemir.wordpress.com/2009/04/27/insight-into-as3-indexed-arrays/</link>
		<comments>http://hozdemir.wordpress.com/2009/04/27/insight-into-as3-indexed-arrays/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 19:27:38 +0000</pubDate>
		<dc:creator>hozdemir</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>

		<guid isPermaLink="false">http://hozdemir.wordpress.com/2009/04/27/insight-into-as3-indexed-arrays/</guid>
		<description><![CDATA[Haluk Ozdemir &#8211; April 2009 Insight into AS3 Indexed Arrays References: Literals: http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_13.html TypedArray implementation: http://livedocs.adobe.com/flex/3/html/10_Lists_of_data_7.html#126815 as3corelib: http://code.google.com/p/as3corelib/ ArrayCollection: http://www.adobe.com/devnet/flex/ learn/content/flp_adobetraining_f3as3_arraycollections.html http://blog.flexdevelopers.com/labels/Jeremy%20Mitchell.html http://blog.flexdevelopers.com/2009/03/flex-basics-arraycollection.html Demo of as3corelib’s ArrayUtil class: http://ntt.cc/2008/09/01/as3corelib-tutorial-how-to-use-arrayutil-class-in-flex.html ArrayUtilities Class from ActionScript 3.0 Cookbook http://rightactionscript.com/ascb. Contains the duplicate() utility; samples can be found in ActionScript 3.0 Cookbook, O’Reilly, 2007. Essential Actionscript 3.0, O’Reilly, 2007. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hozdemir.wordpress.com&amp;blog=7438567&amp;post=25&amp;subd=hozdemir&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="left">Haluk Ozdemir &#8211; April 2009</p>
<h6 align="left"><span style="font-size:large;">Insight into AS3 Indexed Arrays</span></h6>
<p align="left">References:</p>
<p align="left">Literals:    <br /><a href="http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_13.html">http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_13.html</a></p>
<p align="left">TypedArray implementation:    <br /><a href="http://livedocs.adobe.com/flex/3/html/10_Lists_of_data_7.html#126815">http://livedocs.adobe.com/flex/3/html/10_Lists_of_data_7.html#126815</a></p>
<p align="left">as3corelib:    <br /><a href="http://code.google.com/p/as3corelib/">http://code.google.com/p/as3corelib/</a></p>
<p align="left">ArrayCollection:    <br /><a href="http://www.adobe.com/devnet/flex/learn/content/flp_adobetraining_f3as3_arraycollections.html">http://www.adobe.com/devnet/flex/      <br />learn/content/flp_adobetraining_f3as3_arraycollections.html</a>     </p>
<p><a href="http://blog.flexdevelopers.com/labels/Jeremy%20Mitchell.html">http://blog.flexdevelopers.com/labels/Jeremy%20Mitchell.html</a>     <br /><a title="http://blog.flexdevelopers.com/2009/03/flex-basics-arraycollection.html" href="http://blog.flexdevelopers.com/2009/03/flex-basics-arraycollection.html">http://blog.flexdevelopers.com/2009/03/flex-basics-arraycollection.html</a></p>
<p align="left">Demo of as3corelib’s ArrayUtil class:    <br /><a href="http://ntt.cc/2008/09/01/as3corelib-tutorial-how-to-use-arrayutil-class-in-flex.html">http://ntt.cc/2008/09/01/as3corelib-tutorial-how-to-use-arrayutil-class-in-flex.html</a></p>
<p align="left">ArrayUtilities Class from ActionScript 3.0 Cookbook    <br /><a href="http://rightactionscript.com/ascb">http://rightactionscript.com/ascb</a>.     <br />Contains the <em>duplicate()</em> utility; samples can be found in ActionScript 3.0 Cookbook, O’Reilly, 2007.</p>
<p align="left">Essential Actionscript 3.0, O’Reilly, 2007.</p>
<p align="left">Related Reading:</p>
<p align="left">&#160;</p>
<h4 align="left">Overview</h4>
<p align="left">An array – using the term array in its generic sense &#8211; is a container for a set of items. Flex supports the following types of arrays:</p>
<p align="left"><strong>Indexed arrays</strong> use (unsigned) integers to identify the individual entries; we generally refer to an <em>indexed array</em> simply as <em>array</em>. Indexed arrays are implemented by the Array class:</p>
<div align="left">
<pre>	var myArray:Array=new Array();
	myArray[1]=”apple”</pre>
</div>
<p align="left"><strong>Associative arrays</strong>, also called <strong><em>hashes</em></strong>,</p>
<p align="left">use strings to identify the individual entries; in other words, associative arrays contain named elements instead of numbered elements.</p>
<p align="left">Associative arrays are implemented by the Object class.</p>
<div align="left">
<pre>	var myMap = new Object();
	myMap[“name”]=”John”</pre>
</div>
<p align="left">Although Flex allows associative arrays to be constructed using Array class constructor, the resulting object does not have access to the Array class methods or properties.</p>
<p align="left"><strong>Dictionaries</strong> use objects to identify individual entries; the entries are more commonly referred to as key, value pairs. Dictionaries are implemented by the Dictionary class.</p>
<p align="left"><strong>[ ] </strong>is known as the array access operator.</p>
<h4 align="left">Indexed Arrays</h4>
<p align="left">· Each value can be accessed using an unsigned 32-bit integer, using the array access operator [ ].</p>
<p align="left">· Arrays are <strong><em>not typed</em></strong>; one does not declare, for instance, an array of int’s or strings. In fact, the values can be of mixed data type:</p>
<div align="left">
<pre>	myArray[1]=”apple”;
	myArray[2]=20.0;</pre>
</div>
<p align="left">· Arrays are <strong><em>sparse arrays</em>:</strong> there may be an element at index 0 and another at index 9, but nothing in between those two elements. In this case, the elements in positions 1 through 8 are “undefined”, indicating the absence of elements.</p>
<p align="left">· Array is a <strong><em>dynamic</em></strong> class; when deriving classes from Array, the derived class must also be declared dynamic:</p>
<div align="left">
<pre>	public dynamic class TypedArray extends Array
	{
		. . .
	}</pre>
</div>
<p align="left">· Array inherits from Object.</p>
<h4 align="left">Creation using Array class constructor:</h4>
<p align="left">· Using the default constructor, we create an array of length zero:</p>
<div align="left">
<pre>	var myArray= new Array(); //length is 0</pre>
</div>
<p align="left">
  <br />· We can also specify the length when creating the array using the constructor: </p>
<p></p>
<div align="left">
<pre>	var myArray=new Array(10); //length 10; values “undefined”</pre>
</div>
<p align="left">The array size will increase to accommodate new values as they are added; the <span style="font-family:courier new;">length</span> property tells us the size of the array. The <span style="font-family:courier new;">length</span> property can also be set to increase or decrease the array length; setting length equal to zero <em>clears</em> the array.</p>
<p align="left">· Another way to create an indexed array is to provide the initial values in the constructor:</p>
<div align="left">
<pre>	var myArray:Array = new Array (”apple”, 20.0);</pre>
</div>
<p align="left">
  <br />· In MXML, you can create an array as follows: </p>
<p></p>
<div align="left">
<pre>	&lt;mx:Array id=&quot;mxArrayInt&quot;&gt;
		&lt;mx:int&gt;0&lt;/mx:int&gt;
		&lt;mx:int&gt;1&lt;/mx:int&gt;
	&lt;/mx:Array&gt;</pre>
</div>
<h4 align="left">Creation using Array Literals:</h4>
<p align="left"><strong><em>Array literals</em></strong> are enclosed in bracket characters ([]) and use the comma to separate array elements, as in: [“apple”, 20.0] .</p>
<p align="left">Array lterals can be used to create and initialize an Array:</p>
<div align="left">
<pre>	// Assign literal directly; note no ”new”
	var myArray:Array=[];
	var myArray:Array = [”apple”, 20.0];</pre>
</div>
<h4 align="left">Tracing Arrays:</h4>
<p align="left">The <strong>toString</strong>() method of the Array class returns a string that represents the elements in the specified array, with “,” as the separator.</p>
<p align="left">The <em>trace()</em> function can be used directly without first calling toString(), as the toString() method will be automatically invoked for you.</p>
<p align="left">The <strong>join</strong>() method also returns a string, but allows one to specify the separator; the specified separator can be <em>any</em> object, and its string value is used as the separator.</p>
<p align="left">The <strong>split</strong>() method of the String class splits a String object into an array of substrings by dividing it wherever the specified delimiter parameter occurs; in other words, one can join() and then split() to get back the array.</p>
<h4 align="left"><strong>Array Operations:</strong></h4>
<p align="left">We can use arrays as <em>stacks</em> (LIFO):</p>
<ul>
<li>
<div align="left"><strong>push():</strong> uint method will add an element at the end; returns the new length of array. push() takes variable number of args. </div>
</li>
<li>
<div align="left"><strong>pop ():</strong> * method will retrieve the element from the end. </div>
</li>
</ul>
<p align="left">The <strong>unshift()</strong> and <strong>shift()</strong> methods will add and remove, respectively, from the head of the array.</p>
<p align="left">To add or remove one or more element from the middle of the array, use the <strong>splice()</strong> method.</p>
<p align="left">For searches, <strong>indexOf()</strong> and <strong>lastIndexOf()</strong> are available to search using <em>strict equality</em>. See also the ArrayUtilities class methods, provided in the ActionScript 3.0 Cookbook.</p>
<p align="left">Arrays can also be sorted; see the help file for details.</p>
<h4 align="left"><strong>Copying an Array</strong></h4>
<p align="left">We can create a shallow copy of an array by calling either the concat() or slice() methods <em>with no arguments</em>.</p>
<p align="left">The following example, from <strong>ADOBE FLEX 3 Developer Guide, </strong>defines a function named clone() that does deep copying. The function creates a deep copy by serializing the array into an instance of the ByteArray class, and then reading the array back into a new array.</p>
<div align="left">
<pre>	import flash.utils.ByteArray;
	function clone(source:Object):*
	{
		var myBA:ByteArray = new ByteArray();
		myBA.writeObject(source);
		myBA.position = 0;

		return(myBA.readObject());

	}</pre>
</div>
<h4 align="left">Typed Arrays</h4>
<p align="left">The article at:</p>
<p align="left"><a href="http://livedocs.adobe.com/flex/3/html/help.html?content=10_Lists_of_data_3.html">http://livedocs.adobe.com/flex/3/html/help.html?content=10_Lists_of_data_3.html</a></p>
<p align="left">shows how to implement a strongly typed array, and may be useful in shedding light on use of Class class and the apply method of the Function class.</p>
<p align="left">Flash Player 10 has a strongly typed Vector class; see:</p>
<p align="left"><a href="http://blog.skitsanos.com/2008/05/new-vector-actionscript-3s-typed-array.html">http://blog.skitsanos.com/2008/05/new-vector-actionscript-3s-typed-array.html</a></p>
<h4 align="left">Array Collections</h4>
<p align="left">Arrays are not compatible with data binding, because they do not provide a mechanism to :</p>
<ul>
<li>
<div align="left">dispatch an event when data changes </div>
</li>
<li>
<div align="left">allow listeners to subscribe to these events </div>
</li>
</ul>
<p align="left">The ArrayCollection class meets these requirements with the <strong>collectionChange</strong> event and the <strong>addEventListener</strong> method.</p>
<p align="left">An ArrayCollection wraps an Array object.&#160; The ArrayCollection property <strong>source</strong> points the the underlying Array instance. When constructing an ArrayCollection, you can provide the Array or you can set the source property after construction:</p>
<div align="justify">
<pre>	var myArray:Array = new Array(10); //length=10
	var myColl:ArrayCollection = new ArrayCollection(myArray);
	//Alternatively:
	var myOldArray:Array = new Array(10);
	var myColl:ArrayCollection = new ArrayCollection();
	myColl.source = myOldArray;</pre>
</div>
<p align="left">Note that if you create an empty ArrayCollection and add elements using the methods of the ArrayCollection rather than assigning an Array (via the source property), an Array is created for you.</p>
<p align="left">One can get a hold of the underlying Array object through this source property and manipulate the array directly, using the methods of the Array class. If you do this, you must use ArrayCollections’s <strong>refresh()</strong>method to trigger data binding:</p>
<div align="left">
<pre>	myCollection.source.push(&quot;a_string&quot;);
	myCollection.refresh();</pre>
</div>
<p align="left">ArrayCollection is derived from ListCollectionView class,&#160; which implements the ICollectionView and IList interfaces. IList interface&#160; provides add, set, get, and remove operations that operate directly on linear data; these include:</p>
<ul>
<li>
<div align="left">addItem(), addItemAt()</div>
</li>
<li>
<div align="left">setItemAt()</div>
</li>
<li>
<div align="left">getItemAt(), getItemIndex()</div>
</li>
<li>
<div align="left">removeItemAt(), removeAll()</div>
</li>
</ul>
<p align="left">ListCollectionView class also allows the use of [ ] array notation to access the <code>getItemAt()</code> and <code>setItemAt()</code> methods.</p>
<h4>mx.utils.ArrayUtil package</h4>
<p align="left">This class contains two static methods:</p>
<ul>
<li>
<div align="left"><strong>getItemIndex()</strong> returns the index of the item in the array. </div>
</li>
<li>
<div align="left"><strong>toArray()</strong> ensures that an Object can be used as an Array. </div>
</li>
</ul>
<p align="left">(Compare getItemIndex() with indexOf() method of Array class).</p>
<h4 align="left">ArrayUtil Class Methods in as3corelib:</h4>
<p align="left">as3corlib is an opensource project and can be found at:</p>
<p align="left"><a href="http://code.google.com/p/as3corelib/">http://code.google.com/p/as3corelib/</a></p>
<p align="left"><strong>arrayContainsValue ()</strong> method :</p>
<p align="left">Determines whether the specified array contains the specified value.</p>
<p align="left"><strong>arraysAreEqual ()</strong> method :</p>
<p align="left">Compares two arrays and returns a boolean indicating whether the arrays contain the same values at the same indexes.</p>
<p align="left"><strong>copyArray()</strong> method:</p>
<p align="left">Creates a copy of the specified array. Note that the array returned is a new array but the items within the array are not copies of the items in the original array (but rather references to the same items) (note: simply uses slice() for copying).</p>
<p align="left"><strong>createUniqueCopy()</strong> method:</p>
<p align="left">Create a new array that only contains unique instances of objects in the specified array. Basically, this can be used to remove duplication object instances from an array</p>
<p align="left"><strong>removeValueFromArray()</strong> method:</p>
<p align="left">Remove all instances of the specified value from the array</p>
<h4 align="left">ArrayUtilities Class from ActionScript 3.0 Cookbook</h4>
<p align="left">You can get the source code at:</p>
<p align="left"><a href="http://rightactionscript.com/ascb">http://rightactionscript.com/ascb</a>.</p>
<p align="left">For samples, you will need the book.</p>
<p align="left">Adobe.com also has recipes.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hozdemir.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hozdemir.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hozdemir.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hozdemir.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hozdemir.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hozdemir.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hozdemir.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hozdemir.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hozdemir.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hozdemir.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hozdemir.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hozdemir.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hozdemir.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hozdemir.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hozdemir.wordpress.com&amp;blog=7438567&amp;post=25&amp;subd=hozdemir&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hozdemir.wordpress.com/2009/04/27/insight-into-as3-indexed-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab4a8b1537fd5d63112d5807b331f29f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">hozdemir</media:title>
		</media:content>
	</item>
	</channel>
</rss>
