<?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>rel=me &#187; Actionscript</title>
	<atom:link href="http://rel.me/c/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://rel.me</link>
	<description>programming, objective-c, cocoa, iphone, c</description>
	<lastBuildDate>Mon, 02 Aug 2010 20:09:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Actionscript splat (argument unpacking)</title>
		<link>http://rel.me/2008/02/14/actionscript-splat-argument-unpacking/</link>
		<comments>http://rel.me/2008/02/14/actionscript-splat-argument-unpacking/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 21:33:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[argument]]></category>
		<category><![CDATA[splat]]></category>
		<category><![CDATA[unpacking]]></category>

		<guid isPermaLink="false">/2008/03/18/actionscript-splat-argument-unpacking</guid>
		<description><![CDATA[In actionscript there is no splat operator or argument unpacking. In the case where you want to proxy calls to vararg methods you have to use the Function#apply() method. var array:Array = &#91;&#93;; var stuffToAdd:Array = &#91; 1, 2, 3, 4 &#93;; &#160; array.push.apply&#40;array, stuffToAdd&#41;; It would be nice to have a splat/unpack operator: array.push&#40;*stuffToAdd&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>In actionscript there is no <a href="http://redhanded.hobix.com/bits/theSiphoningSplat.html">splat operator</a> or <a href="http://docs.python.org/tut/node6.html#SECTION006740000000000000000">argument unpacking</a>.</p>
<p>In the case where you want to proxy calls to vararg methods you have to use the <a href="http://livedocs.adobe.com/labs/flex3/langref/Function.html#apply()">Function#apply()</a> method.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span class="kw2">var</span> <span class="kw3">array</span>:<span class="kw3">Array</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span>;
<span class="kw2">var</span> stuffToAdd:<span class="kw3">Array</span> = <span class="br0">&#91;</span> <span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span>, <span class="nu0">4</span> <span class="br0">&#93;</span>;
&nbsp;
<span class="kw3">array</span>.<span class="kw3">push</span>.<span class="kw3">apply</span><span class="br0">&#40;</span><span class="kw3">array</span>, stuffToAdd<span class="br0">&#41;</span>;</pre></div></div>

<p>It would be nice to have a splat/unpack operator:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span class="kw3">array</span>.<span class="kw3">push</span><span class="br0">&#40;</span><span class="sy0">*</span>stuffToAdd<span class="br0">&#41;</span>;
<span class="co1">// Or</span>
<span class="kw3">array</span>.<span class="kw3">push</span><span class="br0">&#40;</span>... <span class="me1">stuffToAdd</span><span class="br0">&#41;</span>;</pre></div></div>

<p>The <a href="http://www.google.com/search?q=ecmascript+splat+operator">ecma mailing list</a> discussed this use of <a href="http://www.nabble.com/forum/ViewPost.jtp?post=14450724&#038;framed=y">super.apply(this, arguments)</a>. And specifically regarding argument unpacking in AS3: </p>
<blockquote><p>
We dropped this from AS3 for lack of evidence for its need.
</p></blockquote>
<p>I think any language with <tt>(... args)</tt> to <tt>Array</tt> needs the <tt>Array</tt> to <tt>(... args)</tt> if not for anything other than completeness. Does anyone know if this is planned for ES4 at least?</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2008/02/14/actionscript-splat-argument-unpacking/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Socket output progress in AIR</title>
		<link>http://rel.me/2008/01/17/socket-output-progress-in-air/</link>
		<comments>http://rel.me/2008/01/17/socket-output-progress-in-air/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 19:22:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[socket]]></category>

		<guid isPermaLink="false">/2008/03/18/socket-output-progress-in-air</guid>
		<description><![CDATA[Currently when using the flash.net.Socket api, there is no way to determine that buffered data has been written to the socket. (The flush method is non-blocking and applies only to the actionscript socket buffer). This is a follow-up to a previous post. This issue does not arise when using the new File api (and writing [...]]]></description>
			<content:encoded><![CDATA[<p>Currently when using the flash.net.Socket api, there is no way to<br />
determine that buffered data has been written to the socket. (The flush method is non-blocking and applies only to the actionscript socket buffer).</p>
<p>This is a follow-up to a <a href="http://ducktyper.com/2007/12/27/flush">previous post</a>.</p>
<p>This issue does not arise when using the new File api (and writing to<br />
files), since an event has been included in<br />
<a href="http://livedocs.adobe.com/labs/flex3/langref/flash/filesystem/FileStream.html#eventSummary">flash.filesystem.FileStream: OutputProgressEvent.OUTPUT_PROGRESS</a>
</p>
<p>If this (or a similar) event could be added to the Socket api, it<br />
would allow us to:</p>
<ul>
<li>Send large amounts of data on a socket (without causing large memory<br />
usage as data buffers in memory).</li>
<li>Measure the current progress of data being sent on the socket.</li>
</ul>
<p>We came upon this limitation from using our <a href="http://code.google.com/p/as3httpclientlib/">AS3 http client library</a>, and trying to send large<br />
files as part of a multipart upload. However this issue would arise<br />
when sending any significant amounts of data on a socket. For example, an FTP or bittorrent client would be impossible.</p>
<p>This issue has been discussed in other places, but is probably more<br />
pressing now with the AIR releases.</p>
<ul>
<li><a href="http://tech.groups.yahoo.com/group/flexcoders/message/72018">Getting progress events on Socket *write* (not read)</a></li>
<li><a href="http://www.onflex.org/ted/2007/05/flexftp-ftp-client-in-flex-using.php">FlexFTP &#8211; FTP Client in Flex using flash.net.Socket</a> (see comment by mailboo)</li>
</ul>
<p><b>Update: </b><a href="https://bugs.adobe.com/jira/browse/FP-6">Vote on this bug (FP-6)</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2008/01/17/socket-output-progress-in-air/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>On duck typing and interfaces</title>
		<link>http://rel.me/2008/01/02/on-duck-typing-and-interfaces/</link>
		<comments>http://rel.me/2008/01/02/on-duck-typing-and-interfaces/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 00:59:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[duck typing]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">/2008/04/01/on-duck-typing-and-interfaces</guid>
		<description><![CDATA[I was looking at different type systems (apparently there are 4 dimensions) in different languages and ran across this use of duck typing in C# : For example, the C#&#8217;s foreach operator already uses duck typing. This might be surprising to some, but to support foreach in C# you don&#8217;t need to implement IEnumerable! All [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking at different type systems (apparently there are <a href="http://programming.reddit.com/info/63tnv/comments/c02qx55">4 dimensions</a>) in different languages and ran across this use of <a href="http://blogs.msdn.com/kcwalina/archive/2007/07/18/DuckNotation.aspx">duck typing in C#</a> :</p>
<blockquote><p>
For example, the C#&#8217;s foreach operator already uses duck typing. This might be surprising to some, but to support foreach in C# you don&#8217;t need to implement IEnumerable! All you have to do is:<br/><br />
<br/><br />
Provide a public method GetEnumerator that takes no parameters and returns a type that has two members: a) a method MoveMext that takes no parameters and return a Boolean, and b) a property Current with a getter that returns an Object.
</p></blockquote>
<p>Do you have multiple fine-grained interfaces (like IEnumerable and IEnumerator and ISupportsAdd) or a single interface with all the methods and maybe they throw UnsupportedOperationExceptions if they don&#8217;t actually support a particular call (like in a mutable versus immutable collection)?</p>
<p>The closer you get to more fine grained interfaces like <tt>ISupportsAdd&lt;T&gt;</tt> or <tt>Closeable</tt>, defining a contract for a single method <tt>Add(T obj)</tt> or <tt>Close</tt> is that you might as well just ask the class if it has that method (if it &#8220;quacks&#8221;) instead of whether it implemented a single method interface. Better yet, just assume it and let it throw an error at runtime. Whatever the compiler doesn&#8217;t give you, some decent test coverage will.</p>
<p>But what strikes me as particularly great is that <tt>foreach</tt> is obviously such a powerful thing to restrict to a single interface, and so they chose &#8220;Duck Notation&#8221;, because in this case it is worth it.</p>
<p>This reminded me of why I like ecma 4 (and its derivatives like actionscript). You have freedom to use static and dynamic typing at will.</p>
<p>If you check out my take on an AS3 HTTP client library, <a href="http://as3httpclientlib.googlecode.com/svn/trunk/src/org/httpclient/HttpRequest.as">HttpRequest</a> class and allowing the request body to be of any type:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span class="kw3">public</span> <span class="kw2">class</span> HttpRequest <span class="br0">&#123;</span>
&nbsp;
  <span class="co1">// Request method. For example, &quot;GET&quot;</span>
  protected <span class="kw2">var</span> _method:<span class="kw3">String</span>;
&nbsp;
  <span class="co1">// Request header</span>
  protected <span class="kw2">var</span> _header:HttpHeader;
&nbsp;
  <span class="co1">// Request body</span>
  protected <span class="kw2">var</span> _body:<span class="sy0">*</span>;
&nbsp;
  <span class="coMULTI">/**
   * Create request.
   *  
   * The request body can be anything but should respond to:
   *  - readBytes(bytes:ByteArray, offset:uint, length:uint)
   *  - length
   *  - bytesAvailable
   *  - close
   *  
   * @param method HTTP Method, for example 'GET'
   * @param header HTTP request header (or null)
   * @param body HTTP request body (or null)
   *  
   */</span>
  <span class="kw3">public</span> <span class="kw2">function</span> HttpRequest<span class="br0">&#40;</span>method:<span class="kw3">String</span>, header:HttpHeader = <span class="kw2">null</span>, body:<span class="sy0">*</span> = <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    _method = method;
    _header = header;      
    _body = body;
&nbsp;
 ...</pre></div></div>

<p>I think this is a good choice because:</p>
<ol>
<li>The <a href="http://livedocs.adobe.com/flex/201/langref/flash/utils/IDataInput.html">IDataInput</a> interface (that ByteArray already implements) doesn&#8217;t have a length property and we need to know the request body size (Content-Length) before we send.</li>
<li>The IDataInput interface wants you to implement a ton of read methods, which would make it annoying to force people to implement.</li>
<li>ByteArray has these methods and also implements the length property already. It quacks.</li>
<li>If we created our own interface with these methods, we can&#8217;t add this interface retroactively to ByteArray.</li>
<li>I wrote it. Heh.</li>
</ol>
<p>The other option is to subclass ByteArray and have that implement the new interface, but it just seems awkward (in this case) having any empty subclass solely for the point of enforcing an interface.</p>
<p>Another place where this principle applied for me is in <a href="http://as3httpclientlib.googlecode.com/svn/trunk/src/org/httpclient/HttpSocket.as">HttpSocket</a>. We need to support both Socket (for http) and TLSSocket (for https). TLSSocket has all the same (mostly) methods as Socket (but does not extend Socket; yay for composition over inheritance). Creating a proxy to delegate to different socket implementations based on the http scheme is an option but to me wasn&#8217;t worth it. And using a design pattern to overcome the lack of an appropriate and existing interface just seems to make things worse.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2008/01/02/on-duck-typing-and-interfaces/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Closures</title>
		<link>http://rel.me/2007/12/28/closures/</link>
		<comments>http://rel.me/2007/12/28/closures/#comments</comments>
		<pubDate>Fri, 28 Dec 2007 01:36:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[closure]]></category>

		<guid isPermaLink="false">/2007/12/28/closures</guid>
		<description><![CDATA[There is alot of debate going on between the CICE and BGGA proposals for Java closure support. I thought I would try to experiment with the different proposals and compare to languages I am using right now. I picked something simple to try out, like summing an array of integers: Also check out good closures, [...]]]></description>
			<content:encoded><![CDATA[<p>There is alot of debate going on between the <a href="http://docs.google.com/View?docid=k73_1ggr36h">CICE</a> and <a href="http://www.javac.info/">BGGA</a> proposals for Java closure support. </p>
<p>I thought I would try to experiment with the different proposals and compare to languages I am using right now. I picked something simple to try out, like summing an array of integers:</p>
<p>Also check out <a href="http://blog.opencomponentry.com/2007/12/26/good-closures-bad-closures/">good closures, bad closures</a>.</p>
<h2>Actionscript 3</h2>
<p>Assume you have a reduce function, for example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span class="kw3">public</span> <span class="kw2">function</span> reduce<span class="br0">&#40;</span><span class="kw3">array</span>:<span class="kw3">Array</span>, f:<span class="kw2">Function</span>, <span class="kw3">index</span>:<span class="kw3">int</span> = <span class="nu0">0</span><span class="br0">&#41;</span>:<span class="sy0">*</span> <span class="br0">&#123;</span>
  <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">index</span> == <span class="kw3">array</span>.<span class="kw3">length</span> - <span class="nu0">1</span><span class="br0">&#41;</span> <span class="kw1">return</span> <span class="kw3">array</span><span class="br0">&#91;</span><span class="kw3">index</span><span class="br0">&#93;</span>;
  <span class="kw1">return</span> f<span class="br0">&#40;</span><span class="kw3">array</span><span class="br0">&#91;</span><span class="kw3">index</span><span class="br0">&#93;</span>, reduce<span class="br0">&#40;</span><span class="kw3">array</span>, f, <span class="kw3">index</span> + <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
<span class="br0">&#125;</span></pre></div></div>

<p>Then the syntax is:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span class="kw2">var</span> <span class="kw3">array</span>:<span class="kw3">Array</span> = <span class="br0">&#91;</span> <span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span> <span class="br0">&#93;</span>;
reduce<span class="br0">&#40;</span><span class="kw3">array</span>, <span class="kw2">function</span><span class="br0">&#40;</span>x1:<span class="kw3">Number</span>, x2:<span class="kw3">Number</span><span class="br0">&#41;</span>:<span class="kw3">Number</span> <span class="br0">&#123;</span> <span class="kw1">return</span> x1 + x2; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</pre></div></div>

<h2>Ruby</h2>
<p>Sorry I have to.</a></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span class="kw3">array</span> = <span class="br0">&#91;</span> <span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span> <span class="br0">&#93;</span>;
<span class="kw3">array</span>.<span class="me1">inject</span> <span class="br0">&#123;</span> <span class="sy0">|</span>sum, n<span class="sy0">|</span> sum <span class="sy0">+</span> n <span class="br0">&#125;</span></pre></div></div>

<p>or with <a href="http://api.rubyonrails.org/classes/Symbol.html#M000007">Symbol#to_proc</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span class="kw3">array</span> = <span class="br0">&#91;</span> <span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span> <span class="br0">&#93;</span>;
<span class="kw3">array</span>.<span class="me1">inject</span><span class="br0">&#40;</span><span class="sy0">&amp;</span>:<span class="sy0">+</span><span class="br0">&#41;</span></pre></div></div>

<h2>Java (CICE)</h2>
<p>Assume you have a &#8220;Reducer&#8221; interface (and Collections#reduce):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span class="kw1">interface</span> Reducer<span class="sy0">&lt;</span>T<span class="sy0">&gt;</span> <span class="br0">&#123;</span>
  T reduce<span class="br0">&#40;</span>T t1, T t2<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span class="sy0">&lt;</span>Integer<span class="sy0">&gt;</span> <span class="sy0">=</span> <span class="kw3">Arrays</span>.<span class="me1">asList</span><span class="br0">&#40;</span><span class="br0">&#91;</span> <span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span> <span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw3">Integer</span> sum <span class="sy0">=</span> <span class="kw3">Collections</span>.<span class="me1">reduce</span><span class="br0">&#40;</span>list, Reducer<span class="sy0">&lt;</span>Integer<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="kw3">Integer</span> x1, <span class="kw3">Integer</span> x2<span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="kw1">return</span> x1 <span class="sy0">+</span> x2<span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>I think this is right, help? So you might have to declare new interfaces if the API doesn&#8217;t have them. It would probably have common ones though.</p>
<h2>Java (BGGA)</h2>
<p>Assume you have Collections#reduce:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span class="sy0">&lt;</span>Integer<span class="sy0">&gt;</span> <span class="sy0">=</span> <span class="kw3">Arrays</span>.<span class="me1">asList</span><span class="br0">&#40;</span><span class="br0">&#91;</span> <span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span> <span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw3">Integer</span> sum <span class="sy0">=</span> <span class="kw3">Collections</span>.<span class="me1">reduce</span><span class="br0">&#40;</span>list, <span class="br0">&#123;</span> <span class="kw3">Integer</span> x, <span class="kw3">Integer</span> y <span class="sy0">=&gt;</span> x<span class="sy0">+</span>y <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>The other powerful thing with the BGGA proposal is the control invocations, like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Lock lock <span class="sy0">=</span> <span class="kw1">new</span> Lock<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
Lock.<span class="me1">withLock</span><span class="br0">&#40;</span>lock<span class="br0">&#41;</span> <span class="br0">&#123;</span>
  doSomething<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="co1">// Automatically close stream when done</span>
with<span class="br0">&#40;</span><span class="kw3">FileInputStream</span> f <span class="sy0">:</span> exp<span class="br0">&#41;</span> <span class="br0">&#123;</span>
  doSomething<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>Like in Ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">mutex = <span class="kw4">Mutex</span>.<span class="me1">new</span>
mutex.<span class="me1">synchronize</span> <span class="kw1">do</span>
  doSomething
<span class="kw1">end</span>
&nbsp;
<span class="kw4">File</span>.<span class="kw3">open</span><span class="br0">&#40;</span><span class="st0">&quot;foo.txt&quot;</span>, <span class="st0">&quot;w&quot;</span><span class="br0">&#41;</span> <span class="kw1">do</span> <span class="sy0">|</span>file<span class="sy0">|</span>
  doSomething
<span class="kw1">end</span></pre></div></div>

<p>Since I&#8217;ve been doing Ruby lately, I know which Java proposal I prefer. The CICE doesn&#8217;t address the problem that within an anonymous inner instance <tt>return</tt>, and <tt>this</tt> and any anonymous instance methods are scoped to that anonymous instance and not the enclosing method.</p>
<p>I guess CICE is more about reducing the verbosity of the anonymous instance declaration and allowing mutability on public variables, and its not a real closure in the strict definition. I know people refer to anonymous inner classes as the poor man&#8217;s closure, but I don&#8217;t really think of it as a closure, I think of it as, you know, an anonymous inner class.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/12/28/closures/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Flush</title>
		<link>http://rel.me/2007/12/27/flush/</link>
		<comments>http://rel.me/2007/12/27/flush/#comments</comments>
		<pubDate>Thu, 27 Dec 2007 05:22:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flush]]></category>
		<category><![CDATA[socket]]></category>

		<guid isPermaLink="false">/2008/03/04/flush</guid>
		<description><![CDATA[So I decided to try to overcome the Leopard File.upload() bug by rolling my own http client: as3httpclientlib which even supports https with the TLS (Socket) support from as3crypto (which is great). The HTTP protocol is pretty simple and I figured it would be a good way to learn the internals and look smart reading [...]]]></description>
			<content:encoded><![CDATA[<p>So I decided to try to overcome the Leopard File.upload() <a href="http://www.google.com/search?q=flash+leopard+file+upload">bug</a> by rolling my own http client: <a href="http://code.google.com/p/as3httpclientlib/">as3httpclientlib</a> which even supports https with the TLS (Socket) support from <a href="http://crypto.hurlant.com/">as3crypto</a> (which is great). The HTTP protocol is pretty simple and I figured it would be a good way to learn the internals and look smart reading ancient <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC</a>&#8216;s. All you need is a Socket class and nice, flash api has one at <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/Socket.html">flash.net.Socket<br />
</a></p>
<p>I got everything major working like GET, PUT and POST with multipart/form-data and reading chunked encoding and all that stuff. Not too hard since there are open source http libraries for every major language. I looked at ruby <a href="http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html">Net::HTTP</a> (stole some regex&#8217;s) and <a href="http://hc.apache.org/httpclient-3.x/">Apache Httpclient</a> (stole your multipart boundary).</p>
<p>I got to the point where I was testing uploading larger files, like in:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span class="kw2">var</span> client:HttpClient = <span class="kw2">new</span> HttpClient<span class="br0">&#40;</span><span class="br0">&#41;</span>;
<span class="kw2">var</span> uri:URI = <span class="kw2">new</span> URI<span class="br0">&#40;</span><span class="st0">&quot;http://mybucket.s3.amazonaws.com/big.mp3&quot;</span><span class="br0">&#41;</span>;
<span class="kw2">var</span> testFile:File = <span class="kw2">new</span> File<span class="br0">&#40;</span><span class="st0">&quot;app:/test/assets/big.mp3&quot;</span><span class="br0">&#41;</span>;
client.<span class="me1">upload</span><span class="br0">&#40;</span>uri, testFile<span class="br0">&#41;</span>;</pre></div></div>

<p>It turns out that when you call <tt>_socket.flush()</tt> (in <a href="http://as3httpclientlib.googlecode.com/svn/trunk/src/org/httpclient/HttpSocket.as">HttpSocket</a>) it doesn&#8217;t actually block, which you might expect. After thinking on it, this isn&#8217;t totally shocking since the whole threading model behind actionscript, you don&#8217;t really ever block (like there is no such thing as a modal dialog in flash). The problem is without blocking or an event to notify of a flush, the socket just gets filled with the request body all at once (all 800MB&#8217;s or whatever file size). </p>
<p>It turns out other people ran into this as well. If you look at (<a href="http://maliboo.pl/projects/FlexFTP/">FlexFTP</a>) source, the UploadInv.as file, you will see block of code commented out and replaced by a setInterval(.. , 300). Nice. I guess that upload is capped at ~12kb/sec.</p>
<p>Any of the links in the comments off this <a href="http://www.onflex.org/ted/2007/05/flexftp-ftp-client-in-flex-using.php">blog post</a> are useful too.</p>
<p>If you look at FileStream object you will see it has an <a href="http://livedocs.adobe.com/labs/flex3/langref/flash/filesystem/FileStream.html#event:outputProgress">outputProgressEvent</a> so that would be useful, you know, if Socket had that too.</a></p>
<p>I don&#8217;t know how you get around this issue, other than trying to guess how fast the socket can transmit and try to stay under that. So now I&#8217;m not sure what to do, other than abandon it and come back to it when its fixed, which hopefully will be soon. Thankfully, I can go back to ruby and maybe play with some <a href="http://rubycocoa.sourceforge.net/HomePage">RubyCocoa</a> or <a href="http://code.whytheluckystiff.net/shoes/">Shoes</a> framework.</p>
<p><strong>Update</strong>: Feel free to chime in at <a href="http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=72&#038;catid=641&#038;threadid=1325579&#038;enterthread=y">Adobe Air Forum</a> or <a href="http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform">Feature Request/Bug Report Form</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/12/27/flush/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ASProject and Flash debugging to Firebug console</title>
		<link>http://rel.me/2007/04/12/asproject-and-flash-debugging-to-firebug-console/</link>
		<comments>http://rel.me/2007/04/12/asproject-and-flash-debugging-to-firebug-console/#comments</comments>
		<pubDate>Thu, 12 Apr 2007 02:47:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[asproject]]></category>
		<category><![CDATA[asunit]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">/2007/09/03/asproject-and-flash-debugging-to-firebug-console</guid>
		<description><![CDATA[Publishing, testing, and running Actionscript projects is a pain. &#8220;AsProject automates a variety of tasks including the creation of projects, classes, test cases, test suites, and swfmill libraries. It automates the download, installation and configuration of the debug flash player and many open source tools. AsProject also includes sophisticated build tools written in rake to [...]]]></description>
			<content:encoded><![CDATA[<p>Publishing, testing, and running Actionscript projects is a pain.</p>
<blockquote><p>
&#8220;AsProject automates a variety of tasks including the creation of projects, classes, test cases, test suites, and swfmill libraries. It automates the download, installation and configuration of the debug flash player and many open source tools. AsProject also includes sophisticated build tools written in rake to automate build processes.&#8221;
</p></blockquote>
<p><a href="http://www.asserttrue.com/articles/2007/04/04/introducing-asproject">Video demo</a> or <a href="http://code.google.com/p/asproject/">Project page</a></p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">gem install asproject</pre>
</td>
</tr>
</table>
<p>Also, a friend <a href="http://www.justsuppose.com/">Corey</a> pointed out that you can debug flash using Actionscript ExternalInterface to log to Firebug console.log instead of using ASUnit&#8217;s debug console. In your actionscript: </p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"> ExternalInterface.call(&quot;console.log&quot;, &quot;FLASH: &quot; + s);</pre>
</td>
</tr>
</table>
<p>And make sure to allowScriptAccess.</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">var so = new SWFObject(&quot;flash/xxx.swf&quot;, &quot;myswf&quot;, &quot;680&quot;, &quot;200&quot;, &quot;8&quot;, &quot;#FFFFFF&quot;);<tt>
</tt> so.addParam(&quot;allowScriptAccess&quot;, &quot;always&quot;);<tt>
</tt> so.write(&quot;xxx&quot;);</pre>
</td>
</tr>
</table>
<p>And you could call any javascript from it. <a href="http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00002200.html">ExternalInterface </a> is a replacement for fscommand. I don&#8217;t remember but I don&#8217;t think ExternalInterface works in all browsers.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/04/12/asproject-and-flash-debugging-to-firebug-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
