<?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>Kimkijeung.com &#187; array</title>
	<atom:link href="http://kimkijeung.com/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://kimkijeung.com</link>
	<description>Interactive development,flash,Actionscript,Unity</description>
	<lastBuildDate>Sun, 24 Apr 2011 18:59:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>How to sort Objects(Class)</title>
		<link>http://kimkijeung.com/2007/01/10/how-to-sort-objectsclass/</link>
		<comments>http://kimkijeung.com/2007/01/10/how-to-sort-objectsclass/#comments</comments>
		<pubDate>Tue, 09 Jan 2007 15:01:16 +0000</pubDate>
		<dc:creator>vkimone</dc:creator>
				<category><![CDATA[Flash-AS2.0]]></category>
		<category><![CDATA[Flash-Tip]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[AS2.0]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://vkimone.inblog.kr/?p=380</guid>
		<description><![CDATA[sortOn (Array.sortOn method) public sortOn(fieldName:Object, [options:Object]) : Array Sorts the elements in an array according to one or more fields in the array. The array should have the following characteristics: The array is an indexed array, not an associative array. Each element of the array holds an object with one or more properties. All of [...]]]></description>
			<content:encoded><![CDATA[<div class="signature">
<p><strong><span style="color: #ff0000;">sortOn</span> (Array.sortOn method)<br />
</strong><br />
<span style="color: #0000ff;">public</span> <span style="color: #ff0000;">sortOn</span>(fieldName:Object, [options:<span style="color: #ff0000;">Object</span>]) : <span style="color: #ff0000;">Array</span></div>
<p>Sorts the elements in an array according to one or more fields in the array. The array should have the following characteristics:</p>
<li>The array is an indexed array, not an associative array.</li>
<li><span style="color: #0000ff;">Each element of the array holds an object with one or more properties.</span><span style="color: #ff0000;"> </span></li>
<li>All of the objects have at least one property in common, the values of which can be used to sort the array. Such a property is called a <em>field</em>.If you pass multiple <code>fieldName</code> parameters, the first field represents the primary sort field, the second represents the next sort field, and so on. Flash sorts according to Unicode values. (ASCII is a subset of Unicode.) If either of the elements being compared does not contain the field that is specified in the <code>fieldName</code> parameter, the field is assumed to be <code>undefined</code>, and the elements are placed consecutively in the sorted array in no particular order.오브젝트를 일반적인 단일속성이 아닌 한개 이상의 여러 속성을 기준으로 정렬할시 사용되는 메서드이다. 오브젝트를 정렬할때 종종 사용하던 방법이였는데 이번 프로젝트를 진행하면서 클래스 자체를 정렬할때 사용해 보았는데 제대로 작동하였다.
<p>클래스는 당연히 오브젝트의 일종이다. 따라서 클래스 안에 있는 멤버 변수들을 기준으로 정렬이 가능하다는 의미다. 자신이 클래스를 사용하여 이미지 갤러리같은 정렬의 기능이 있는 컨텐츠를 제작할시에 아주 유용한 기능일 것이다.</p>
<p><strong>// widget class : 정렬에 사용될 클래스</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> com.<span style="color: #006600;">dstrict</span>.<span style="color: #006600;">UB</span>.<span style="color: #006600;">project</span>.<span style="color: #006600;">ces2007</span>.<span style="color: #006600;">widget</span>.<span style="color: #006600;">Widget</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> _id:<span style="color: #0066CC;">String</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> _title:<span style="color: #0066CC;">String</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> _date:<span style="color: #0066CC;">Number</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Widget<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">String</span>,title:<span style="color: #0066CC;">String</span>,<span style="color: #0066CC;">date</span>:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  _id=id;
  _title=title;
  _date=<span style="color: #0066CC;">date</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">// example code</span>
&nbsp;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">dstrict</span>.<span style="color: #006600;">UB</span>.<span style="color: #006600;">project</span>.<span style="color: #006600;">ces2007</span>.<span style="color: #006600;">widget</span>.<span style="color: #006600;">Widget</span> ;
<span style="color: #000000; font-weight: bold;">var</span> widgetArr:<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>;
<span style="color: #000000; font-weight: bold;">var</span> widget1:Widget=<span style="color: #000000; font-weight: bold;">new</span> Widget<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;vkimone&quot;</span>,<span style="color: #ff0000;">&quot;widget1&quot;</span>,<span style="color: #cc66cc;">20061213</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> widget2:Widget=<span style="color: #000000; font-weight: bold;">new</span> Widget<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;kimkijeung&quot;</span>,<span style="color: #ff0000;">&quot;widget2&quot;</span>,<span style="color: #cc66cc;">20061110</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> widget3:Widget=<span style="color: #000000; font-weight: bold;">new</span> Widget<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Tom&quot;</span>,<span style="color: #ff0000;">&quot;widget3&quot;</span>,<span style="color: #cc66cc;">20061115</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> widget4:Widget=<span style="color: #000000; font-weight: bold;">new</span> Widget<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Jane&quot;</span>,<span style="color: #ff0000;">&quot;widget4&quot;</span>,<span style="color: #cc66cc;">20061211</span><span style="color: #66cc66;">&#41;</span>;
widgetArr.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>widget1<span style="color: #66cc66;">&#41;</span>;
widgetArr.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>widget2<span style="color: #66cc66;">&#41;</span>;
widgetArr.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>widget3<span style="color: #66cc66;">&#41;</span>;
widgetArr.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>widget4<span style="color: #66cc66;">&#41;</span>;
<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: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>widgetArr.<span style="color: #0066CC;">length</span> ; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>i+<span style="color: #ff0000;">&quot;  : &quot;</span>+widgetArr<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>._id+<span style="color: #ff0000;">&quot; : &quot;</span>+widgetArr<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>._title+<span style="color: #ff0000;">&quot;  -----------&gt;&quot;</span>+widgetArr<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>._date<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;======================================&quot;</span><span style="color: #66cc66;">&#41;</span>;
widgetArr.<span style="color: #0066CC;">sortOn</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;_date&quot;</span>,<span style="color: #0066CC;">Array</span>.<span style="color: #006600;">NUMERIC</span><span style="color: #66cc66;">|</span> <span style="color: #0066CC;">Array</span>.<span style="color: #006600;">DESCENDING</span><span style="color: #66cc66;">&#41;</span>;
<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: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>widgetArr.<span style="color: #0066CC;">length</span> ; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>i+<span style="color: #ff0000;">&quot;  : &quot;</span>+widgetArr<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>._id+<span style="color: #ff0000;">&quot; : &quot;</span>+widgetArr<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>._title+<span style="color: #ff0000;">&quot;  -----------&gt;&quot;</span>+widgetArr<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>._date<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>//result</strong><br />
0  : vkimone : widget1  &#8212;&#8212;&#8212;&#8211;&gt;20061213<br />
1  : kimkijeung : widget2  &#8212;&#8212;&#8212;&#8211;&gt;20061110<br />
2  : Tom : widget3  &#8212;&#8212;&#8212;&#8211;&gt;20061115<br />
3  : Jane : widget4  &#8212;&#8212;&#8212;&#8211;&gt;20061211<br />
======================================<br />
0  : vkimone : widget1  &#8212;&#8212;&#8212;&#8211;&gt;20061213<br />
1  : Jane : widget4  &#8212;&#8212;&#8212;&#8211;&gt;20061211<br />
2  : Tom : widget3  &#8212;&#8212;&#8212;&#8211;&gt;20061115<br />
3  : kimkijeung : widget2  &#8212;&#8212;&#8212;&#8211;&gt;20061110</p>
<p>각각의 아이디값과 제목 그리고 날짜 정보를 포함하는 widget 클래스에서 여러개의 객체를 생성한후<br />
배열에 넣은 다음 오브젝트 속성인 _date 를 기준으로 내림차순으로 숫자 정렬했을때의 결과값이다.<br />
각 클래스 속성을 기준으로 통채로 정렬이 된다.</p>
<p>만역 클래스를 이용해 철저히 오브젝트들을 캡슐화(encapsulation)했다면 손쉽게 오브젝트 정렬을 사용할 수 있을 것이다.</li>
]]></content:encoded>
			<wfw:commentRss>http://kimkijeung.com/2007/01/10/how-to-sort-objectsclass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

