<?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>iprashant</title>
	<atom:link href="http://iprashant.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://iprashant.com/blog</link>
	<description>rand(thoughts)</description>
	<lastBuildDate>Sat, 04 Jul 2009 15:13:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>customizing the datechooser to make dates draggable and double clickable</title>
		<link>http://iprashant.com/blog/?p=24</link>
		<comments>http://iprashant.com/blog/?p=24#comments</comments>
		<pubDate>Sat, 04 Jul 2009 15:06:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[date chooser]]></category>
		<category><![CDATA[double click]]></category>
		<category><![CDATA[drag date]]></category>

		<guid isPermaLink="false">http://iprashant.com/blog/?p=24</guid>
		<description><![CDATA[In my current project on Flex, I came up with a requirement of customizing the current DateChooser control and add following functionalities:
add double clickable functionality for days and know which particular day is double clicked upon double clicked
allow user to drag day from the date chooser and drop over other controls as a date
By default [...]]]></description>
			<content:encoded><![CDATA[<p>In my current project on Flex, I came up with a requirement of customizing the current DateChooser control and add following functionalities:<br />
add double clickable functionality for days and know which particular day is double clicked upon double clicked<br />
allow user to drag day from the date chooser and drop over other controls as a date</p>
<p>By default the Flex 3 DateChooser control allows you to select a date, range of dates, or multiple dates. So i had to extend the default datechoose controls and after playing with the codes, i finally achieved what required. Lets have a look at the control first.</p>
<p>
<object width="450" height="300">
<param name="movie" value="http://iprashant.com/uploads/AdvancedDateChooserComponent.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="450" height="300" src="http://iprashant.com/uploads/AdvancedDateChooserComponent.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>You can double click a day which will show you an alert saying which date is double clicked. You can even drag a day and drop over the list control on the right side which will eventually add the dropped date from the date chooser control. Lets have a look at the code now. The code below shows the custom datechooser class that extends the <strong>mx.controls.DateChooser</strong> which incorporates the behaviors i just discussed above.</p>
<pre class="brush: actionscript3;">
package com.iprashant
{
	import flash.events.MouseEvent;

	import mx.controls.Alert;
	import mx.controls.DateChooser;
	import mx.controls.Image;
	import mx.core.DragSource;
	import mx.core.UIComponent;
	import mx.core.UITextField;
	import mx.core.mx_internal;
	import mx.managers.DragManager;

	use namespace mx_internal;

	public class AdvancedDateChooser extends DateChooser {

		private var recentMouseDownEvent:MouseEvent;

		public function AdvancedDateChooser() {
			super();
			addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
		}

		protected override function createChildren() : void {
			super.createChildren();
			var dateGrid:UIComponent = mx_internal::dateGrid;
			dateGrid.doubleClickEnabled = true;
			dateGrid.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler);
			dateGrid.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
			dateGrid.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
		}

		private function doubleClickHandler(event:MouseEvent) : void {
			var dayNum:Number = Number(event.target.text);
			if(event.target is UITextField &amp;&amp; dayNum != 0) {
				var dateDoubleClicked:Date = new Date(displayedYear, displayedMonth, event.target.text);
				Alert.show(&quot;Double clicked date is: &quot; + dateDoubleClicked.toDateString());
			}
		}

		private function mouseUpHandler(event:MouseEvent) : void {
			recentMouseDownEvent = null;
		}

		private function mouseDownHandler(event:MouseEvent) : void {
			var dayNum:Number = Number(event.target.text);
			dayNum = dayNum == 0?NaN:dayNum;
			if(event.target is UITextField &amp;&amp; !isNaN(dayNum)) {
				recentMouseDownEvent = event;
			}
		}

		private function mouseMoveHandler(event:MouseEvent) : void {
			if(event.buttonDown &amp;&amp; recentMouseDownEvent != null &amp;&amp; !DragManager.isDragging &amp;&amp; (Math.abs(recentMouseDownEvent.stageX - event.stageX) &gt;= 5 || Math.abs(recentMouseDownEvent.stageY - event.stageY) &gt;= 5)) {
				var dragSource:DragSource = new DragSource();
				var date:Date = new Date(displayedYear, displayedMonth, recentMouseDownEvent.target.text);
				dragSource.addData(date, &quot;date&quot;);
				var imageProxy:Image = new Image();
                imageProxy.source = dateImage;
                imageProxy.height=16;
                imageProxy.width=16;
                DragManager.doDrag(UIComponent(event.currentTarget), dragSource, event, imageProxy, (event.currentTarget.x-event.target.x), (event.currentTarget.y-event.target.y) - 25, 1.00);
				recentMouseDownEvent = null;
			}
		}
	}
}
</pre>
<p>If you check the source code of the <strong>mx.controls.DateChooser</strong>, you will come to know that it arranges the days on the control in the datagrid. So I first fetched the reference of the DataGrid control used in the DateChooser which happens to be the mx_internal variable. mx_internal is a namespace used in Flex SDK for functions, variables likely to change in future releases. To know more about the mx_internal namespace, you can click <a href="http://codeofdoom.com/wordpress/2009/03/12/when-and-how-to-use-mx_internal-in-flex/" target="_blank">here</a>.</p>
<p>Have a look at the function <strong>createChildren()</strong> to find out how i obtained the reference of the dataGrid used in the DateChooser control and added a listner for the double click event on the data grid control of the date chooser. On the double click listener function, i check to see if the target of the event is the UITextField that is used to show the day. I fetch the text property from the target property of the double click event. Using the day on which double click occurs and the <strong>displayedYear</strong> and <strong>displayedMonth</strong> properties, i get the double clicked date.</p>
<p>For the draggable functionality of the date from the date chooser, have a look at the functions &#8211; <strong>mouseUpHandler</strong>, <strong>mouseDownHandler</strong> and <strong>mouseMoveHandler</strong>. To start the dragging, i used the combination of mouseMoveHandler and mouseDownHandler. The dragging starts only when mouse is down on the box used to show day and few pixels moved. You can check on the &#8220;if&#8221; condition inside the mouseMoveHandler to figure out how i achieved that.</p>
<p>To download the code click <a href="http://iprashant.com/uploads/AdvancedDateChooserComponent.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iprashant.com/blog/?feed=rss2&amp;p=24</wfw:commentRss>
		<slash:comments>304</slash:comments>
		</item>
		<item>
		<title>Hello Again!</title>
		<link>http://iprashant.com/blog/?p=1</link>
		<comments>http://iprashant.com/blog/?p=1#comments</comments>
		<pubDate>Sat, 20 Jun 2009 05:18:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://iprashant.com/blog/?p=1</guid>
		<description><![CDATA[Pheww!! At last, i was successful to make the wordpress work. I have been trying to install it since yesterday but could not complete the installation successfully due to slow as well as unstable internet connection.
I have been blogging in http://iprashant.blogger.de (in fact i haven&#8217;t been blogging at all lately   ). You will [...]]]></description>
			<content:encoded><![CDATA[<p>Pheww!! At last, i was successful to make the wordpress work. I have been trying to install it since yesterday but could not complete the installation successfully due to slow as well as unstable internet connection.</p>
<p>I have been blogging in <a href="http://iprashant.blogger.de" target="_blank">http://iprashant.blogger.de</a> (in fact i haven&#8217;t been blogging at all lately <img src='http://iprashant.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). You will find pretty old posts but definitely useful if you are a flex developers just stepped into the world of adobe flex.</p>
<p>Recently I got my own domain name (iprashant.com) and thanks to my brother (<a href="http://klash-design.com" target="_blank">Kailash</a>), he provided me some space to host the files. So i decided to put an end to my blogging in http://iprashant.blogger.de and move to http://iprashant.com.</p>
<p>I am pretty sluggish when it comes to blogging. Once i read about 10 blogger types from <a href="http://www.highrankings.com/10-blogger-types" target="_blank">http://www.highrankings.com/10-blogger-types</a>. I don&#8217;t want to blog just for the sake of blogging and fall into the category10 and don&#8217;t even want to republish the same thing just to increase the number of posts. So i will blog when somethings come up worth sharing.</p>
<p>Happy Blogging!!</p>
]]></content:encoded>
			<wfw:commentRss>http://iprashant.com/blog/?feed=rss2&amp;p=1</wfw:commentRss>
		<slash:comments>205</slash:comments>
		</item>
	</channel>
</rss>

