<?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>masputih &#187; Freebies</title>
	<atom:link href="http://masputih.com/category/freebies/feed" rel="self" type="application/rss+xml" />
	<link>http://masputih.com</link>
	<description>Coder for Hire</description>
	<lastBuildDate>Mon, 24 May 2010 08:48:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Array Paginator Class</title>
		<link>http://masputih.com/2010/03/array-paginator-class</link>
		<comments>http://masputih.com/2010/03/array-paginator-class#comments</comments>
		<pubDate>Thu, 25 Mar 2010 13:17:23 +0000</pubDate>
		<dc:creator>Anggie Bratadinata</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Freebies]]></category>
		<category><![CDATA[actionscript]]></category>

		<guid isPermaLink="false">http://masputih.com/?p=729</guid>
		<description><![CDATA[Here’s a class to paginate an Array with convenient functions like pageUp(), pageDown(), peek(), etc. package { /** * * @author Anggie Bratadinata */ public class ArrayPaginator { private var _target:Array; private var _pageSize:int = 0; private var _totalPage:int = 0; private var _pageIndex:int = 0; private var _currentPage:Array; private var _targetLength:int; private var _pagedArray:Array; [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Here’s a class to paginate an Array with convenient functions like <code>pageUp()</code>, <code>pageDown()</code>, <code>peek()</code>, etc.</p>
<p><span id="more-729"></span></p>
<pre class="brush:as3" >
package
{

	/**
	 *
	 * @author Anggie Bratadinata
	 */
	public class ArrayPaginator
	{
		private var _target:Array;
		private var _pageSize:int = 0;
		private var _totalPage:int = 0;

		private var _pageIndex:int = 0;
		private var _currentPage:Array;
		private var _targetLength:int;
		private var _pagedArray:Array;

		public function ArrayPaginator()
		{

		}

		/**
		 * Build a paginated array using a copy of the target array and return the first page.
		 * Later modifications to the target array will not be reflected unless this function is revoked.
		 *
		 * @param	target				The array to be paginated
		 * @param	pageSize			The number of items in each page
		 * @param 	forceFullContent	Force all pages to contain equal number of items
		 * @param	pageFiller			Object to fill a page that has less number of items than the intended page size. Ignored if forceFullContent is false.
		 * @return
		 */
		public function paginate(target:Array, pageSize:int = 1, forceFullContent:Boolean = false, pageFiller:* = null):Array
		{

			if (pageSize < 1) {
				throw new ArgumentError("pageSize can't be less than 1");
				return;
			}

			_target = target.concat();
			_targetLength = _target.length;
			_pageSize = pageSize;

			_totalPage = Math.ceil(_targetLength / _pageSize);

			if (forceFullContent)
			{
				var fillCount:int = (_totalPage * _pageSize) - _targetLength;

				if (fillCount > 0)
				{
					for (var j:int = 0; j < fillCount; j++)
					{
						_target.push(pageFiller);
					}

					_targetLength = _target.length;
				}
			}

			_pagedArray = [];

			for (var i:int = 0; i < _targetLength; i = i + _pageSize )
			{
				var sub:Array = _target.slice(i, i + _pageSize);
				_pagedArray.push(sub);
			}

			return firstPage;

		}

		/**
		 * Go to a page and get its content.
		 *
		 * @param	pageNum		Page number from 1 to total page.
		 * @return 	Array Page content
		 */
		public function getPage(pageNum:int):Array
		{
			var idx:int = pageNum - 1;
			var a:Array = _pagedArray[idx];

			if (a != null)
			{
				_pageIndex = idx;
				_currentPage = a;
			}

			return a;
		}

		/**
		 * Go to the next page and get its content.
		 * @return Array
		 */
		public function pageUp():Array
		{
			if (currentPageNum == _totalPage)
			{
				return currentPage;
			}

			return getPage(currentPageNum + 1);
		};

		/**
		 * Go to the previous page and get its content.
		 * @return Array
		 */
		public function pageDown():Array
		{
			if (currentPageNum == 1)
			{
				return currentPage;
			}

			return getPage(currentPageNum - 1);
		};

		/**
		 * Get the content of the last page without moving the page pointer.
		 * @return Array
		 */
		public function peekLast():Array
		{
			return peekPage(_totalPage);
		}

		/**
		 * Get the content of the first page without moving the page pointer.
		 * @return Array
		 */
		public function peekFirst():Array
		{
			return peekPage(1);
		}

		/**
		 * Get the content of the next page without moving the page pointer.
		 * @return Array
		 */
		public function peekUp():Array
		{
			return peekPage(currentPageNum + 1);
		}

		/**
		 * Get the content of the previous page without moving the page pointer.
		 * @return Array
		 */
		public function peekDown():Array
		{
			return peekPage(currentPageNum - 1);
		}

		/**
		 * Get the content of a page without moving the page pointer.
		 * @param 	pageNum  Page number from 1 to total page
		 * @return Array
		 */
		public function peekPage(pageNum:int):Array
		{
			var p:Array = _pagedArray[pageNum - 1];
			return p;
		}

		/**
		 * Get all pages.
		 * @return Array
		 */
		public function get pages():Array
		{
			return _pagedArray;
		}

		/**
		 * Go to the last page and get the content
		 * @return Array The page content
		 */
		public function get lastPage():Array
		{
			return getPage(_totalPage);
		};

		/**
		 * Go to the first page and get the content
		 * @return Array The page content
		 */
		public function get firstPage():Array
		{
			return getPage(1);
		};

		/**
		 * Get the current page number
		 */
		public function get currentPageNum():int
		{
			return _pageIndex + 1;
		}

		/**
		 * Get the total number of pages.
		 */
		public function get totalPage():int
		{
			return _totalPage;
		}

		/**
		 * Get the content of the current page.
		 * @return Array
		 */
		public function get currentPage():Array
		{
			return _currentPage;
		}

		/**
		 * True if the current page is the last page
		 */
		public function get isLast():Boolean
		{
			return (currentPageNum == _totalPage);
		}

		/**
		 * True if the current page is the first page
		 */
		public function get isFirst():Boolean
		{
			return (currentPageNum == 1);
		}
	}

}
</pre>
<h4>Sample Usage</h4>
<pre class="brush:as3">
private function onAddedToStage(e:Event):void
{
	removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

	target = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
	paginator = new ArrayPaginator();
	trace("first page " + paginator.paginate(target, 4));
	trace("num of pages " + paginator.totalPage);

	timer = new Timer(3000);
	timer.addEventListener(TimerEvent.TIMER, onTimer);
	timer.start();
}

public var isUp:Boolean = true;

private function onTimer(e:TimerEvent):void
{
	if (paginator.isFirst) {
		isUp = true;
	} else	if(paginator.isLast) {
		isUp = false;
	}

	if (isUp) {
		paginator.pageUp() ;
	}else {
		paginator.pageDown();
	}
	trace('/-------/');
	trace("page " + paginator.currentPageNum + " : " + paginator.currentPage.join(','));
	trace("next page " + paginator.peekUp());
	trace("prev page " + paginator.peekDown());
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://masputih.com/2010/03/array-paginator-class/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scattered Gallery</title>
		<link>http://masputih.com/2009/12/scattered-gallery</link>
		<comments>http://masputih.com/2009/12/scattered-gallery#comments</comments>
		<pubDate>Mon, 14 Dec 2009 14:21:48 +0000</pubDate>
		<dc:creator>Anggie Bratadinata</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Freebies]]></category>

		<guid isPermaLink="false">http://masputih.com/?p=660</guid>
		<description><![CDATA[A free flash gallery with randomly distributed pictures. Written in pure AS3. Compiled with Flex SDK. Uses an XML to specify image URLs and caption text Click on an empty space to randomly redistribute the pictures. Click on a picture to see it in its real size. Click on it again to scale it down. [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>A free flash gallery with randomly distributed pictures. Written in pure AS3. Compiled with Flex SDK.</p>
<ul>
<li>Uses an XML to specify image URLs and caption text</li>
<li>Click on an empty space to randomly redistribute the pictures.</li>
<li>Click on a picture to see it in its real size. Click on it again to scale it down.</li>
<li>Pictures are draggable.</li>
</ul>
<p><span id="more-660"></span><br />
The main code is free to use for any purpose. No warranty. Feel free to ask if you have any questions.</p>
<p>Note that this application uses 3rd-party libraries (TweenLite and MonsterDebugger). Please consult their licenses as well.</p>
<div id="attachment_661" class="wp-caption aligncenter" style="width: 355px">
	<a href="http://labs.masputih.com/scattered-gallery/" rel="shadowbox"><img src="http://masputih.com/wordpress/wp-content/uploads/2009/12/scattered-gallery.jpg" alt="Click to view the demo" title="Scattered Gallery" width="355" height="328" class="size-full wp-image-661" /></a>
	<p class="wp-caption-text">Click to view the demo</p>
</div>
<blockquote>
<h4>Download</h4>
<a href="http://masputih.com/wordpress/wp-content/plugins/download-monitor/download.php?id=scattered-gallery.zip" title="Downloaded 200 times">→ Scattered Gallery</a></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://masputih.com/2009/12/scattered-gallery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
