<?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>House of Metnetsky &#187; flash</title>
	<atom:link href="http://cowarthill.com/blog/index.php/tag/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://cowarthill.com/blog</link>
	<description>Run Tortoise Run</description>
	<lastBuildDate>Fri, 26 Feb 2010 17:15:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Replacing Flex&#8217;s Timer with Event.ENTER_FRAME</title>
		<link>http://cowarthill.com/blog/index.php/2009/02/05/replacing-flexs-timer-with-event-enter-frame/</link>
		<comments>http://cowarthill.com/blog/index.php/2009/02/05/replacing-flexs-timer-with-event-enter-frame/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 03:54:23 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=125</guid>
		<description><![CDATA[One of the projects I&#8217;m working on, as you might have guessed, utilizes Adobe&#8217;s AIR. After reading a few dozen optimization tips it sounded like I needed to replace four internal Timer&#8216;s because they aren&#8217;t very efficient. As I couldn&#8217;t find anything off-hand that suited my needs I rolled my own (with some optimizations by [...]]]></description>
			<content:encoded><![CDATA[<p>One of the projects I&#8217;m working on, as you might have guessed, utilizes Adobe&#8217;s <a href="http://www.adobe.com/products/air/" target="_blank">AIR</a>. After reading a <a href="http://www.craftymind.com/2008/11/20/max-2008-session-material/" target="_blank">few</a> dozen <a href="http://spreadingfunkyness.com/garbage-collection-with-flex-and-adobe-air/" target="_blank">optimization</a> tips it sounded like I needed to replace four internal <a href="http://livedocs.adobe.com/flex/3/langref/flash/utils/Timer.html" target="_blank">Timer</a>&#8216;s because they aren&#8217;t very efficient. As I couldn&#8217;t find anything off-hand that suited my needs I rolled my own (with some optimizations by Noah Massey).</p>
<p>The original code looked similar to:</p>
<pre class="brush: jscript; title: ; notranslate">
private var timer:Timer = new Timer(15000); // run every 15 seconds

private function onCreation(event:Event):void {
	this.timer.addEventListener(TimerEvent.TIMER, this.onTimer, false, 0, true);
	this.timer.start();
}

private function onTimer(event:TimerEvent):void {
	/* do something */
}
</pre>
<p>I didn&#8217;t want to totally refactor all of my code because that would have been an amazing waste of time. So I ran through my usage of &#8220;timer&#8221; and realized what I needed to be able to do:</p>
<ul>
<li>start</li>
<li>stop</li>
<li>change interval</li>
<li>create run-once functions like setTimeout, but tied to frames</li>
</ul>
<p>With this in mind I typed up what I wanted and after a bit of tweaking my usage now looks like this:</p>
<pre class="brush: jscript; title: ; notranslate">
private function onCreation(event:Event):void {
	FrameActivity.assign('someName', 15, this.onTimer);

	this.addEventListener(Event.ENTER_FRAME, FrameActivity.handleFrame, false, 0, true);
}

private function onTimer(event:Event):void {
	/* do something */
}
</pre>
<p>If you like what you see, send me a comment and I&#8217;ll happily provide the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2009/02/05/replacing-flexs-timer-with-event-enter-frame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Reflection</title>
		<link>http://cowarthill.com/blog/index.php/2009/01/28/as-reflection/</link>
		<comments>http://cowarthill.com/blog/index.php/2009/01/28/as-reflection/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 22:48:57 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[kmbs]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=117</guid>
		<description><![CDATA[Type discovery, better known as reflection, is rather odd in Flex. There is no type system to describe the types like sooo many languages offer (even PHP5 finally got it right). The closest that I know of is flash.utils.describeType which is quite weird as it returns XML. The DTD for the XML is ugly to [...]]]></description>
			<content:encoded><![CDATA[<p>Type discovery, better known as reflection, is rather odd in Flex. There is no type system to describe the types like sooo many languages offer (even <a href="http://us.php.net/oop5.reflection" target="_blank">PHP5</a> finally got it right). The closest that I know of is <a  target="_blank"  href="http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#describeType()">flash.utils.describeType</a> which is quite weird as it returns <a href="http://livedocs.adobe.com/flex/3/langref/XML.html"  target="_blank">XML</a>. The DTD for the XML is ugly to me, but everyone has their opinions. A simple class like..</p>
<pre class="brush: jscript; title: ; notranslate">
public final class EmployeeTitle extends BaseModel
{
	public var id:Number = NaN;
	public var title:String = '';

	public function EmployeeTitle()
	{
		super();
	}

	public static function fromXML(xml:XML):EmployeeTitle
	{
		return null; /* we should do something important here */
	}
}
</pre>
<p>turns into the following XML&#8230;</p>
<pre class="brush: xml; title: ; notranslate">
&lt;type name=&quot;kmbs.model::EmployeeTitle&quot; base=&quot;kmbs.model::BaseModel&quot; isDynamic=&quot;false&quot; isFinal=&quot;true&quot; isStatic=&quot;false&quot;&gt;
  &lt;extendsClass type=&quot;kmbs.model::BaseModel&quot;/&gt;
  &lt;extendsClass type=&quot;Object&quot;/&gt;
  &lt;variable name=&quot;id&quot; type=&quot;Number&quot;/&gt;
  &lt;variable name=&quot;title&quot; type=&quot;String&quot;/&gt;
  &lt;method name=&quot;assignXML&quot; declaredBy=&quot;kmbs.model::BaseModel&quot; returnType=&quot;void&quot;&gt;
    &lt;parameter index=&quot;1&quot; type=&quot;XML&quot; optional=&quot;false&quot;/&gt;
  &lt;/method&gt;
  &lt;method name=&quot;toString&quot; declaredBy=&quot;kmbs.model::BaseModel&quot; returnType=&quot;String&quot;/&gt;
  &lt;method name=&quot;toXML&quot; declaredBy=&quot;kmbs.model::BaseModel&quot; returnType=&quot;XML&quot;/&gt;
&lt;/type&gt;
</pre>
<p>As I was looking for a way to marshal the type to XML for pushing to the server it seems like this was the closest I was going to get. So I wrote some code and got the basics working no problem. A few days ago I realized that most of my models would be a bit more useful if they were [Bindable] and thus dispatched events about their changes (lets keep those interfaces up to date eh?). So I added what .NET calls attributes and Flex calls metadata tags.. [Bindable] to my class.</p>
<pre class="brush: jscript; title: ; notranslate">
[Bindable]
public final class EmployeeTitle extends BaseModel
{
	/* .... */
}
</pre>
<p>Once I did this however, none of my XML marshaling was working because apparently the type descriptor is now <strong>totally</strong> different.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;type name=&quot;kmbs.model::EmployeeTitle&quot; base=&quot;kmbs.model::BaseModel&quot; isDynamic=&quot;false&quot; isFinal=&quot;true&quot; isStatic=&quot;false&quot;&gt;
  &lt;extendsClass type=&quot;kmbs.model::BaseModel&quot;/&gt;
  &lt;extendsClass type=&quot;Object&quot;/&gt;
  &lt;implementsInterface type=&quot;flash.events::IEventDispatcher&quot;/&gt;
  &lt;method name=&quot;addEventListener&quot; declaredBy=&quot;kmbs.model::EmployeeTitle&quot; returnType=&quot;void&quot;&gt;
    &lt;parameter index=&quot;1&quot; type=&quot;String&quot; optional=&quot;false&quot;/&gt;
    &lt;parameter index=&quot;2&quot; type=&quot;Function&quot; optional=&quot;false&quot;/&gt;
    &lt;parameter index=&quot;3&quot; type=&quot;Boolean&quot; optional=&quot;true&quot;/&gt;
    &lt;parameter index=&quot;4&quot; type=&quot;int&quot; optional=&quot;true&quot;/&gt;
    &lt;parameter index=&quot;5&quot; type=&quot;Boolean&quot; optional=&quot;true&quot;/&gt;
  &lt;/method&gt;
  &lt;accessor name=&quot;id&quot; access=&quot;readwrite&quot; type=&quot;Number&quot; declaredBy=&quot;kmbs.model::EmployeeTitle&quot;&gt;
    &lt;metadata name=&quot;Bindable&quot;&gt;
      &lt;arg key=&quot;event&quot; value=&quot;propertyChange&quot;/&gt;
    &lt;/metadata&gt;
  &lt;/accessor&gt;
  &lt;method name=&quot;hasEventListener&quot; declaredBy=&quot;kmbs.model::EmployeeTitle&quot; returnType=&quot;Boolean&quot;&gt;
    &lt;parameter index=&quot;1&quot; type=&quot;String&quot; optional=&quot;false&quot;/&gt;
  &lt;/method&gt;
  &lt;method name=&quot;dispatchEvent&quot; declaredBy=&quot;kmbs.model::EmployeeTitle&quot; returnType=&quot;Boolean&quot;&gt;
    &lt;parameter index=&quot;1&quot; type=&quot;flash.events::Event&quot; optional=&quot;false&quot;/&gt;
  &lt;/method&gt;
  &lt;method name=&quot;willTrigger&quot; declaredBy=&quot;kmbs.model::EmployeeTitle&quot; returnType=&quot;Boolean&quot;&gt;
    &lt;parameter index=&quot;1&quot; type=&quot;String&quot; optional=&quot;false&quot;/&gt;
  &lt;/method&gt;
  &lt;method name=&quot;removeEventListener&quot; declaredBy=&quot;kmbs.model::EmployeeTitle&quot; returnType=&quot;void&quot;&gt;
    &lt;parameter index=&quot;1&quot; type=&quot;String&quot; optional=&quot;false&quot;/&gt;
    &lt;parameter index=&quot;2&quot; type=&quot;Function&quot; optional=&quot;false&quot;/&gt;
    &lt;parameter index=&quot;3&quot; type=&quot;Boolean&quot; optional=&quot;true&quot;/&gt;
  &lt;/method&gt;
  &lt;accessor name=&quot;title&quot; access=&quot;readwrite&quot; type=&quot;String&quot; declaredBy=&quot;kmbs.model::EmployeeTitle&quot;&gt;
    &lt;metadata name=&quot;Bindable&quot;&gt;
      &lt;arg key=&quot;event&quot; value=&quot;propertyChange&quot;/&gt;
    &lt;/metadata&gt;
  &lt;/accessor&gt;
  &lt;method name=&quot;assignXML&quot; declaredBy=&quot;kmbs.model::BaseModel&quot; returnType=&quot;void&quot;&gt;
    &lt;parameter index=&quot;1&quot; type=&quot;XML&quot; optional=&quot;false&quot;/&gt;
  &lt;/method&gt;
  &lt;method name=&quot;toString&quot; declaredBy=&quot;kmbs.model::BaseModel&quot; returnType=&quot;String&quot;/&gt;
  &lt;method name=&quot;toXML&quot; declaredBy=&quot;kmbs.model::BaseModel&quot; returnType=&quot;XML&quot;/&gt;
&lt;/type&gt;
</pre>
<p>As you can see all of the variable tags have been replaced by accessor tags. And methods have been added in order to perform the Event handling/dispatching, but apparently the class doesn&#8217;t extend something special. Instead the compiler seemingly injects raw methods, which bothers me for some reason.</p>
<p>As you can see I find Flex&#8217;s internals rather <strong>weird</strong> instead of <strong>smart</strong>, but as I said, everyone has their opinions.</p>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2009/01/28/as-reflection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monthly Calendars in PHP for Flex</title>
		<link>http://cowarthill.com/blog/index.php/2009/01/21/php-flex-xml-calendar/</link>
		<comments>http://cowarthill.com/blog/index.php/2009/01/21/php-flex-xml-calendar/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 01:00:05 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[kmbs]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=96</guid>
		<description><![CDATA[At work I recently had a need to create a monthly calendar within Flex and populated with data from a web-service (created in PHP). I hate reinventing the wheel, but I also hate wasting time searching for a solution to a simple enough problem. So below you can find a quick answer to the problem [...]]]></description>
			<content:encoded><![CDATA[<p>At work I recently had a need to create a monthly calendar within Flex and populated with data from a web-service (created in PHP). I hate reinventing the wheel, but I also hate wasting time searching for a solution to a simple enough problem. So below you can find a quick answer to the problem as I couldn&#8217;t find one myself.</p>
<p><strong>PHP</strong>: The following code creates a simple XML feed.</p>
<hr />
<pre class="brush: php; title: ; notranslate">
&lt;?php
	/**
	 * Create a XML calendar for a given year &amp;amp; month
	 *
	 * Noah Massey &amp;amp; Matthew Metnetsky
	 */
	function calendar_xml($doc, $year, $month)
	{
		if (!$doc) throw new Exception('doc is bad');
		if (!$month) throw new Exception('month  is bad');
		if (!$year) throw new Exception('year is bad');

		$numDays = date('t', mktime(0, 0, 0, $month, 1, $year));

		$monthNode = $doc-&gt;appendChild($doc-&gt;createElement('month'));

		$day = 1 - date('w', mktime(0, 0, 0, $month, 1, $year));

		do {
			$weekNode = $monthNode-&gt;appendChild($doc-&gt;createElement('week'));

			for ($y=0;$y&lt;7 and $day &lt;= $numDays; $day++,$y++) {
				//$sunday = ($day == $y);
				//$sunday = ($day == ($y + 6));
				$dayNode = $weekNode-&gt;appendChild($doc-&gt;createElement('day'));
				$numAttr = $doc-&gt;createAttribute('num');
				$numAttr-&gt;appendChild($doc-&gt;createTextNode($day));
				$dayNode-&gt;appendChild($numAttr);

				/*
				 * we could loop through database records here for holidays etc
				 * the _real_ version uses mktime(0, 0, 0, $month, $day, $year)
				 * to check for a stamp within an array of holiday records
				 * and then tack on some more nodes to $dayNode
				 */
			}
		} while ($day &lt;= $numDays);
	}

	$doc = new DOMDocument('1.0', 'UTF-8');
	$doc-&gt;formatOutput = true;

	$date = getdate();
	$year = (int) (array_key_exists('year', $_GET))? $_GET['year'] : $date['year'];
	$month = (int) (array_key_exists('month', $_GET))? $_GET['month'] : $date['mon'];

	calendar_xml($doc, $year, $month);
	header('Content-Type: application/xml', true);
	echo($doc-&gt;saveXML());
?&gt;
</pre>
<p>If you look at the rather large comment block above you can see where the value comes in. It&#8217;s pretty simple to use a unix timestamp to find records which you actually would want in the XML like holidays, events, etc.</p>
<p>The basic output looks like the following, and can be see in full at <a target="_blank" href="http://cowarthill.com/blog/wp-content/uploads/2009/01/calendar-xml.php">http://cowarthill.com/blog/wp-content/uploads/2009/01/calendar-xml.php</a></p>
<pre class="brush: xml; title: ; notranslate">
	&lt;month&gt;
		&lt;week&gt;
			&lt;day num=&quot;{day of month}&quot; /&gt;
		&lt;/week&gt;
	&lt;/month&gt;
</pre>
<hr />
Once you have all of this in place you need to pull it into Flex. I found using a DataGrid very easy once you have the XML from the web service. And to customize the display I created a custom itemRenderer for the DataGridColumns. Here&#8217;s a few snippets&#8230;.</p>
<p><strong>MXML:</strong> Lets define our DataGrid and our HTTPService which will retrieve our data.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;mx:DataGrid id=&quot;dg&quot;
	sortableColumns=&quot;false&quot;
	draggableColumns=&quot;false&quot;
	selectable=&quot;false&quot;
	showScrollTips=&quot;true&quot;
	horizontalScrollPolicy=&quot;off&quot;
	verticalScrollPolicy=&quot;off&quot;&gt;
	&lt;mx:columns&gt;
		&lt;mx:DataGridColumn headerText=&quot;Sunday&quot; itemRenderer=&quot;calendar.MonthCell&quot; /&gt;
		&lt;mx:DataGridColumn headerText=&quot;Monday&quot; itemRenderer=&quot;calendar.MonthCell&quot; /&gt;
		&lt;mx:DataGridColumn headerText=&quot;Tuesday&quot; itemRenderer=&quot;calendar.MonthCell&quot; /&gt;
		&lt;mx:DataGridColumn headerText=&quot;Wednesday&quot; itemRenderer=&quot;calendar.MonthCell&quot; /&gt;
		&lt;mx:DataGridColumn headerText=&quot;Thursday&quot; itemRenderer=&quot;calendar.MonthCell&quot;  /&gt;
		&lt;mx:DataGridColumn headerText=&quot;Friday&quot; itemRenderer=&quot;calendar.MonthCell&quot; /&gt;
		&lt;mx:DataGridColumn headerText=&quot;Saturday&quot; itemRenderer=&quot;calendar.MonthCell&quot; /&gt;
	&lt;/mx:columns&gt;
&lt;/mx:DataGrid&gt;

&lt;mx:HTTPService id=&quot;calHS&quot;
	url=&quot;http://localhost/project/calendar-xml.php&quot;
	method=&quot;GET&quot;
	result=&quot;handleCalXML(event);&quot;
	fault=&quot;Alert.show('Failed to retrieve XML from server');&quot;
	resultFormat=&quot;e4x&quot;
	contentType=&quot;application/xml&quot;/&gt;
</pre>
<p><strong>AS3:</strong> Now we need at least two functions: 1 to call the service and retrieve the XML; and a second take the response and assign it to the DataGrid.</p>
<pre class="brush: jscript; title: ; notranslate">
/* month should be 1-based (January) */
public function retrieveCalendar():void
{
	calHS.url = 'http://localhost/project/calendar-xml.php?year=' + year + '&amp;amp;month=' + month;
	calHS.send();
}

/* handle the results from from calendar-xml.php */
private function handleCalXML(event:ResultEvent):void
{
	var weeks:XMLList = event.result.week as XMLList;

	/* dg is defined above in the MXML */
	this.dg.dataProvider = dayInfo;
	this.dg.rowCount = weeks.length(); // grid show be no bigger than necessary
}
</pre>
<p>Now we&#8217;re going to create a reusable itemRenderer which is instantiated for each cell in the DataGrid. You can do this in MXML directly, but I like AS3. The most important function to focus on is the setter for data because it assigns the values based on the XML we received.</p>
<pre class="brush: jscript; title: ; notranslate">
package calendar
{
	import mx.collections.XMLListCollection;
	import mx.controls.TextArea;
	import mx.controls.listClasses.BaseListData;
	import mx.controls.listClasses.IDropInListItemRenderer;
	import mx.controls.listClasses.IListItemRenderer;
	import mx.core.IDataRenderer;
	import mx.events.FlexEvent;

	public class MonthCell  extends TextArea
							implements IDataRenderer, IDropInListItemRenderer, IListItemRenderer
	{
		private var _week:XMLListCollection = null;
		private var _day:XML = null;
		private var _listData:BaseListData;

		public function MonthCell()
		{
			super();

			this.editable = false;
			this.wordWrap = true;
			this.selectable = false;
		}

		[Bindable(FlexEvent.DATA_CHANGE)]
		public override function get listData():BaseListData
		{
			return this._listData;
		}

		public override function set listData(ldata:BaseListData):void
		{
			if (this._listData != ldata) {
			this._listData = ldata;
			this.dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
			}
		}

		[Bindable(FlexEvent.DATA_CHANGE)]
		public override function get data():Object
		{
			return this._week;
		}

		public override function set data(value:Object):void
		{
			var xml:XML = value as XML;

			if (xml) {
				// convert XML to a list for extra methods
				this._week = new XMLListCollection(xml.children());

				// make sure we've got enough records in week
				// to be able to get the current day
				if (this._week.length &gt; this.listData.columnIndex) {
					this._day = this._week.getItemAt(this.listData.columnIndex) as XML;
				} else {
					this._day = null; // clear in-case we're reused
				}
			}

			// do we have a valid day XML object
			if (this._week == null || this._day == null || int(this._day.@num) &lt; 1) {
				this.htmlText = &quot;&quot;;
			} else {
				/* lets display the day of the month in the cell */
				this.htmlText = &quot;&lt;p&gt;&lt;b&gt;&quot; + this._day.@num + &quot;&lt;/b&gt;&lt;/p&gt;&quot;;
			}

			this.invalidateProperties();
			this.dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2009/01/21/php-flex-xml-calendar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Filtering File Selectors</title>
		<link>http://cowarthill.com/blog/index.php/2009/01/17/filtering-file-selectors/</link>
		<comments>http://cowarthill.com/blog/index.php/2009/01/17/filtering-file-selectors/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 17:54:27 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=16</guid>
		<description><![CDATA[Why is it that almost every language/framework offers totally different, and yet similar, solutions for filtering in/out files from selection menus? .NET In the example there are two types of selectors: text files (.txt); all files (*.*). Labels (Text files) are separated from their filter values (*.txt) by the pipe character and each filter type [...]]]></description>
			<content:encoded><![CDATA[<p>Why is it that almost every language/framework offers totally different, and yet similar, solutions for filtering in/out files from selection menus?</p>
<hr />
<h3>.NET</h3>
<pre class="brush: csharp; title: ; notranslate">OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = &quot;Text files (*.txt)|*.txt|All files (*.*)|*.*&quot;</pre>
<p>In the example there are two types of selectors: text files (.txt); all files (*.*). Labels (Text files) are separated from their filter values (*.txt) by the pipe character and each filter type is separated by&#8230; a pipe too! It looks weird, but considering it&#8217;s based off old-school Windows API I can understand and sort of respect their desire to not change. MFC sucks and using weird DSLs instead of creating more objects can have it&#8217;s <em>benefits</em>.</p>
<hr />
<h3>Flash</h3>
<pre class="brush: jscript; title: ; notranslate">var filters:Array = new Array();
filters.push(new FileFilter('Text Files', '*.txt'));
filters.push(new FileFilter('Rich Text', '*.rtf'));

var file:flash.net.FileReference = new FileReference();
file.browse(filters);</pre>
<p>FileFilter is constructed with the rules like so: FileFilter(&#8216;Text Files&#8217;, &#8216;*.txt&#8217;). You can either specify multiple FileFilters or append multiple rulsets to the same label like so: FileFilter(&#8216;Text files&#8217;, &#8216;*.txt;*.txt2&#8242;). Truly a cleaner interface than .NET&#8217;s, but many could argue it&#8217;s Object over kill (AWT/SWING is probably worse).</p>
<hr />
<h3>Gtk+</h3>
<pre class="brush: cpp; title: ; notranslate">GtkFileFilter *file_filter = gtk_file_filter_new();
gtk_file_filter_set_name(file_filter, &quot;Log Files (*.bab)&quot;);
gtk_file_filter_add_pattern(file_filter, &quot;*.bab&quot;);</pre>
<p>Even though Gtk+ is in C, it has a nice interface (which many languages like Flash could be accused of robbing). The name is different than the pattern, and there aren&#8217;t ugly crazy separators like in .NET/MFC.</p>
<hr />
<h3>Swing</h3>
<pre class="brush: java; title: ; notranslate">ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension(&quot;jpg&quot;);
filter.addExtension(&quot;gif&quot;);
filter.setDescription(&quot;JPG &amp;amp;amp;amp; GIF Images&quot;);

JFileChooser dialog = new JFileChooser();
dialog.setFileFilter(filter);</pre>
<p>This isn&#8217;t too bad until you realize that <a title="ExampleFileFilter" href="http://kickjava.com/src/demo/swingset/ExampleFileFilter.java.htm" target="_blank">ExampleFileFilter</a> is a custom class which extends abstract <a title="FileFilter" href="http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/filechooser/FileFilter.html" target="_blank">FileFilter</a>. Yes there are other ways, but boy is this annoying!</p>
<hr />
<h3>Python (Gtk+)</h3>
<pre class="brush: python; title: ; notranslate">
        dialog = gtk.FileChooserDialog(title=&quot;Select the World&quot;
                            , action=gtk.FILE_CHOOSER_ACTION_OPEN
                            , buttons=(gtk.STOCK_CANCEL
                                                    , gtk.RESPONSE_CANCEL
                                                    , gtk.STOCK_OPEN
                                                    , gtk.RESPONSE_OK))
        filter = gtk.FileFilter()
        filter.set_name(&quot;All files&quot;)
        filter.add_pattern(&quot;*&quot;)
        dialog.add_filter(filter)
</pre>
<p>Just like Gtk+ but with the Python-esk feel.</p>
<hr />
<h3>Conclusion</h3>
<p>I must be stating the obvious: Framework developers hate programmers.</p>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2009/01/17/filtering-file-selectors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE7, IE8 Beta2&#8230; meet &lt;object/&gt;</title>
		<link>http://cowarthill.com/blog/index.php/2008/11/25/ie7-ie8-beta2-meet-object/</link>
		<comments>http://cowarthill.com/blog/index.php/2008/11/25/ie7-ie8-beta2-meet-object/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 01:26:57 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[ie7]]></category>
		<category><![CDATA[ie8]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=27</guid>
		<description><![CDATA[Why is it that IE7 and IE8 Beta 2 still can&#8217;t quit get the &#60;object/&#62; tag correct? When using Javascript to &#8220;dynamically&#8221; add object tags to the interface my experience, bad luck, and bouts of pain teach me that using the DOM API just doesn&#8217;t cut it. Well, to be fair the following functions don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Why is it that IE7 and IE8 Beta 2 still can&#8217;t quit get the &lt;object/&gt; tag correct? When using Javascript to &#8220;dynamically&#8221; add object tags to the interface my experience, bad luck, and bouts of pain teach me that using the DOM API just doesn&#8217;t cut it. Well, to be fair the following functions don&#8217;t cut it:</p>
<ul>
<li>document.createElement</li>
<li>document.createAttribute</li>
<li>[DOMElement].setAttribute(key, value)</li>
<li>[DOMElement].setAttributeNode([DOMAttribute])</li>
</ul>
<p>For any and all other &#8220;dynamic&#8221; HTML modifications the above functions work great! But if I use them to embed Flash or Silverlight movies it just tanks. Instead you have to construct ugly strings that represent the HTML you want and use [DOMElement].innerHTML. When you do this, suddenly the .swf/.xap loads and all is well.</p>
<p>Why oh why?</p>
<p>And for anyone who cares, following file does a decent job of HTML generation within Javascript&#8230; except for IE and the &lt;object/&gt; tag&#8230;. and input of type radio (WTF!).</p>
<p><a href="http://cowarthill.com/blog/wp-content/uploads/2008/11/html_obj.js">http://cowarthill.com/blog/wp-content/uploads/2008/11/html_obj.js</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2008/11/25/ie7-ie8-beta2-meet-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight vs. Flash</title>
		<link>http://cowarthill.com/blog/index.php/2008/11/24/silverlight-vs-flash/</link>
		<comments>http://cowarthill.com/blog/index.php/2008/11/24/silverlight-vs-flash/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 00:03:15 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[kmbs]]></category>
		<category><![CDATA[printgroove]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=3</guid>
		<description><![CDATA[I&#8217;ve been a long time hater of Flash as a web-service consumer because of its inability to use any HTTP method other than GET or POST. People revert to stupid URL argument tricks like ?_method=DELETE and actually use a GET or POST, neither of which work if your service layer is actually &#8230; truly &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been a long time hater of Flash as a web-service consumer because of its inability to use any HTTP method other than GET or POST. People revert to stupid URL argument tricks like ?_method=DELETE and actually use a GET or POST, neither of which work if your service layer is actually &#8230; truly &#8230; RESTful.</p>
<p>Silverlight has the same damn issue. Apparently none of the blog posts I read a WHILE back (2+ yrs) mentioned the fact that Flash, and now Silverlight, use the lowest common denominator for their web request classes&#8230;. NPAPI (Gecko/Mozilla Plugin SDK). I&#8217;m sure there are good reasons for using the embedded ones, security, re-usability, performance too &#8211; but it&#8217;s rather annoying!</p>
<p>Why the NPAPI developers don&#8217;t augment the API, I have no idea. But at least Silverlight allows for a HTML event to trigger the OpenFileDialog.ShowDialog() without having to do fun invisible overlays.</p>
<p>Silverlight:<br />
<a class="moz-txt-link-freeext" href="http://wilcob.com/Wilco/Silverlight/http-requests-in-silverlight.aspx">http://wilcob.com/Wilco/Silverlight/http-requests-in-silverlight.aspx</a></p>
<p>Flash:<a class="moz-txt-link-freetext" href="http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html#head34"></p>
<p>http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html#head34</p>
<p></a><a class="moz-txt-link-freetext" href="http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html">http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html<br />
</a><a class="moz-txt-link-freetext" href="http://theflashblog.com/?p=423">http://theflashblog.com/?p=423</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2008/11/24/silverlight-vs-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

