<?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>WireLust &#187; flash</title>
	<atom:link href="http://www.wirelust.com/category/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wirelust.com</link>
	<description>Technology and stuff, you know.</description>
	<lastBuildDate>Thu, 27 May 2010 05:37:52 +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>10+ things Flash can do that HTML5 can&#8217;t</title>
		<link>http://www.wirelust.com/2010/05/21/10-things-flash-can-do-today-that-html5-cant/</link>
		<comments>http://www.wirelust.com/2010/05/21/10-things-flash-can-do-today-that-html5-cant/#comments</comments>
		<pubDate>Fri, 21 May 2010 15:57:48 +0000</pubDate>
		<dc:creator>Tea</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.wirelust.com/?p=491</guid>
		<description><![CDATA[In face of all the hype, fear, confusion related to HTML5 vs Flash I wanted to come up with a reasoned list of why I think flash is still the right choice for building many types of web applications. This is a list of things I could think of and find that highlight some areas [...]]]></description>
			<content:encoded><![CDATA[<p>In face of all the hype, fear, confusion related to HTML5 vs Flash I wanted to come up with a reasoned list of why I think flash is still the right choice for building many types of web applications. This is a list of things I could think of and find that highlight some areas where Flash has innovated ahead of where the HTML5 specs and implementations are at currently.</p>
<h3>1. Touch interface support</h3>
<p>Despite what Apple says, flash applications that were designed to work with rollovers work really well when used on a touch based interface. (<a href="http://theflashblog.com/?p=2027">see video here</a>). Apple neglects to mention that rollovers are super common with HTML/js sites now and none of the mobile web browsers handle them particularly well. In addition, Flash ships with a full API for multi-touch that developers can use. HTML5 multi-touch support is still being worked out and is in very early stages of being implemented.</p>
<h3>2. More Audio Codecs</h3>
<p>Flash supports ADPCM, HE-AAC, MP3, WAV, Nellymoser, and Speex codecs. HTML5 defines an audio tag and leaves it up to the browser to decide what Codecs to support. Where does that leave you? As of this writing, Firefox will be supporting OGG and WAV, Chrome supporting OGG and MP3, IE supporting MP3 and AAC. To build a site with HTML5 you will have to choose your codecs carefully and make sure that users are using a compatible browser. As an aside, it is also possible to write pure AS3 decoders, so there is <a href="http://barelyfocused.net/blog/2008/10/03/flash-vorbis-player/">an OGG vorbis</a> player written completely in Flash.  </p>
<h3>3. More Video Codecs</h3>
<p>A lot like the story with audio, Flash supports multiple video codecs (On2 VP6, Sorenson Spark, and H.264). HTML5 leaves it up to the browser to support codecs so as a developer you have to know what browser your user is using and choose an appropriate codec. Encoding your video twice once for Firefox and once for IE is going to be painful. Even sites that are moving to HTML5/H.264 are using Flash as a fallback for browsers that don&#8217;t support H.264.</p>
<h3>4. Color Correction</h3>
<p>This doesn&#8217;t mean a whole ton to me, and might not to you, but there are people out there for which color correction is a very big deal. If you were building a workflow application for professional photographers for instance, having built in color correction could make a ton of difference.</p>
<h3>5. Manipulate Binary Data</h3>
<p>Actionscript 3 is capable of manipulating raw binary data. This enables you to do things like extend it to handle more file formats, network protocols, or media codecs. Javascript cannot yet handle binary data and I don&#8217;t see a proposal anywhere that would enable it to do so.</p>
<h3>6. Peer-2-Peer</h3>
<p>P2P is in the <a href="http://www.w3.org/TR/2008/WD-html5-20080122/#network" target="_blank">HTML5 spec</a> but as of this writing isn&#8217;t implemented in any browsers. Flash supports P2P out of the box with frameworks to assist in helping you build applications that use it. P2P enables you to have end users send data to each other without a need for a central server. For example, if you had a video chat service, you wouldn&#8217;t want every user to stream their video to a central server to be connected. The load on your central server would be huge. You would instead have users that are communicating with each other connect directly to each other to transfer the video.</p>
<h3>7. Binary Network Sockets</h3>
<p>Like P2P, Web Sockets will take care of most of your networking needs, but it can&#8217;t handle binary data (or work over UDP). This limits the type of applications you can write.  Also, as of this writing, Web Sockets is only implemented in Google Chrome.</p>
<h3>8. Use the Webcam or Microphone</h3>
<p>The Device APIs and Policy Working Group is supposed to be working on a recommendation for this, but there goal is to deliver a standard by Mid 2011. Once that is complete, browser makers can begin conform to this standard. If you want an application where users record photos, audio, or video &#8211; Flash is still your best choice.</p>
<h3>9. Video Streaming</h3>
<p>This one seems to confuse a lot of people that I talk to because they don&#8217;t realize that Flash has two mechanisms to service Video/Audio. You can host your media on a plain old web server and have it play as it downloads, or you can host it with an RTMP server and have it stream to the user. Streaming allows you to do things like bitrate adjustments (adjusting quality depending on the user&#8217;s speed) and jump around in a file. For example, when you click in the middle of a 2 hour long movie on HULU, the player jumps right to that point and starts playing. If you had this long movie hosted on a normal web server for download you would have to wait until the entire video up to that point has been downloaded.</p>
<p>HTML5 only defines the HTTP download type as part of the standard. There are specs out there  for getting progressive streaming working with HTML5 but they aren&#8217;t all completely implemented and aren&#8217;t part of the core HTML5 standard.</p>
<h3>10. Media Digital Rights Management</h3>
<p>There are tons of different solutions out there for better protecting your content with Flash. I haven&#8217;t yet seen any DRM methods that work with HTML5. When I bring this up with discussions I get an earful about how DRM is evil and who cares if it isn&#8217;t supported. I tend to agree that DRM has issues and I&#8217;m not thrilled to have to use it, but try telling that to your boss who owns the content. Wether we like it or not, DRM is a requirement for many people who are serving up the content wether we object to it or not.</p>
<h3>11. Built in Accessibility support</h3>
<p>Developers often overlook accessibility but anyone who has worked on a site for a large corporation knows that this is a real concern since having a website that is not usable by disabled users opens them up to lawsuits. Flash supports Microsoft&#8217;s Active Accessibility (MSAA) API. As well as TimedText closed captioning for video subtitles.</p>
<p>Critics have rightly complained that this support only works on windows but the number of screen readers on OSX and Linux is limited and less standardized, so I see Adobe&#8217;s choice here. </p>
<p>I don&#8217;t see any mention of Accessibility in any of the HTML5 proposals. (let me know if it is there). I&#8217;m sure it will be trivial to write javascript that parses TimedText and syncs it with video but I would really have liked to see something about CC in the specs.</p>
<h3>12. Massive community supported library set</h3>
<p>This is an area where HTML5/javascript is catching up, but it is still a long way off. The flash community is massive and has tons of open source libraries for building almost anything you can imagine. </p>
<h3>13. Full screen mode</h3>
<p><span style="color:red">Late Entry: 5/27/2010</span><br />
HTML5 prohibits browsers from making any way to programmatically enter full screen mode. It allows browsers to provide a way to view video full screen but not other elements. With Flash a user click action can trigger full screen of any content. While some talk, legitimately, about security concerns &#8211; this feature is used successfully by many sites out there to deliver a better user experience.  Full screen mode is used not just for video viewing, but for Kiosks, presentations, and many multimedia rich sites I&#8217;ve seen. I have also not heard of any nefarious sites in the wild using full screen to try to trick users. The combination of click to activate and escape to exit seem to do a pretty good job of offering an okay balance of security and utility.</p>
<h3>There you have it</h3>
<p>There you have it, 12 things I can think of that continue to make Flash the right choice for many projects. I&#8217;m going to keep the list titled 10 because some people will complain that #12 isn&#8217;t a feature of the platform and who makes lists of 11 things.</p>
<p>For the record, I&#8217;m not an HTML5 hater. I use whatever technology is best for any given job. I look forward to more standards, more openness, and more cool new tech. On those fronts HTML5 is looking more awesome by the day, but if I want to write an app now and now next year, it isn&#8217;t the right choice for everything.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wirelust.com/2010/05/21/10-things-flash-can-do-today-that-html5-cant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Image Cropping with Flex</title>
		<link>http://www.wirelust.com/2010/01/06/simple-image-cropping-with-flex/</link>
		<comments>http://www.wirelust.com/2010/01/06/simple-image-cropping-with-flex/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 15:37:20 +0000</pubDate>
		<dc:creator>Tea</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[cs4]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.wirelust.com/?p=370</guid>
		<description><![CDATA[Here is a simple, pure as3, image cropper I wrote for Flex. I&#8217;ll try do a post later in the week describing how to use it in Flash cs3 and cs4. 
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_main_1323495961"
			class="flashmovie"
			width="640"
			height="458">
	<param name="movie" value="http://www.wirelust.com/apps/flex_image_crop/bin-debug/main.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.wirelust.com/apps/flex_image_crop/bin-debug/main.swf"
			name="fm_main_1323495961"
			width="640"
			height="458">
	<!--<![endif]-->
		 
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object> Features: Very Simple Allows you to set min and max values for height and [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple, pure as3, image cropper I wrote for Flex.  I&#8217;ll try do a post later in the week describing how to use it in Flash cs3 and cs4.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_main_1889506414"
			class="flashmovie"
			width="640"
			height="458">
	<param name="movie" value="http://www.wirelust.com/apps/flex_image_crop/bin-debug/main.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.wirelust.com/apps/flex_image_crop/bin-debug/main.swf"
			name="fm_main_1889506414"
			width="640"
			height="458">
	<!--<![endif]-->
		
<p><img src="/apps/flex_image_crop/flex_image_crop_20100106.jpg" alt="screenshot for people without flash"/></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><strong>Features:</strong></p>
<ul>
<li>Very Simple</li>
<li>Allows you to set min and max values for height and width</li>
<li>Holding shift key keeps aspect ratio</li>
</ul>
<p>You currently have to do the cropping on your own, either in flash or server side.  I will followup later with examples of how to do that.</p>
<p>To embed this into you application, all you have to do is:<br />
<pre class="actionscript"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">wirelust</span>.<span style="color: #006600;">imagecrop</span>.<span style="color: #006600;">ImageCrop</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">wirelust</span>.<span style="color: #006600;">imagecrop</span>.<span style="color: #006600;">CropBox</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageCrop:ImageCrop = <span style="color: #000000; font-weight: bold;">new</span> ImageCrop<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onCreationComplete<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	imageCrop.<span style="color: #006600;">loadImage</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;demo1.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;
	
	<span style="color: #808080; font-style: italic;">// imageBox is an mx:HBox in my mxml</span>
	imageBox.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>imageCrop<span style="color: #66cc66;">&#41;</span>;
	
	<span style="color: #000000; font-weight: bold;">var</span> crop:CropBox = imageCrop.<span style="color: #006600;">cropBox</span>;
	
	<span style="color: #808080; font-style: italic;">// Set up the initial crop</span>
	crop.<span style="color: #006600;">cropX</span> = <span style="color: #cc66cc;">178</span>;
	crop.<span style="color: #006600;">cropY</span> = <span style="color: #cc66cc;">187</span>;
	crop.<span style="color: #006600;">cropWidth</span> = <span style="color: #cc66cc;">249</span>;
	crop.<span style="color: #006600;">cropHeight</span> = <span style="color: #cc66cc;">219</span>;
<span style="color: #66cc66;">&#125;</span></pre></p>
<p>You can then listen for CropBox.EVENT_CHANGED to get the dimensions of the box as it changes:</p>
<p><pre class="javascript"><span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> onCreationComplete<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #000066; font-weight: bold;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #009900; font-style: italic;">// snipped ...</span>
	
	crop.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>CropBox.<span style="color: #006600;">EVENT_CHANGED</span>, onCropChanged<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> onCropChanged<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #000066; font-weight: bold;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>imageCrop.<span style="color: #006600;">cropBox</span> != <span style="color: #003366; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		xValue.<span style="color: #006600;">text</span> = imageCrop.<span style="color: #006600;">cropBox</span>.<span style="color: #006600;">cropX</span>.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		yValue.<span style="color: #006600;">text</span> = imageCrop.<span style="color: #006600;">cropBox</span>.<span style="color: #006600;">cropY</span>.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		widthValue.<span style="color: #006600;">text</span> = imageCrop.<span style="color: #006600;">cropBox</span>.<span style="color: #006600;">cropWidth</span>.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		heightValue.<span style="color: #006600;">text</span> = imageCrop.<span style="color: #006600;">cropBox</span>.<span style="color: #006600;">cropHeight</span>.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></p>
<h3>Files</h3>
<p><a href="http://www.wirelust.com/apps/flex_image_crop/flex_image_crop_20100106.zip"><img src="http://www.wirelust.com/img/famfamicons/icons/page_white_put.png" border="0"></a>&nbsp;<a href="http://www.wirelust.com/apps/flex_image_crop/flex_image_crop_20100106.zip">Download source code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wirelust.com/2010/01/06/simple-image-cropping-with-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[snippit] &#8211; generating a faux waveform in AS3</title>
		<link>http://www.wirelust.com/2009/12/08/snippit-generating-a-faux-waveform-in-as3/</link>
		<comments>http://www.wirelust.com/2009/12/08/snippit-generating-a-faux-waveform-in-as3/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 21:22:52 +0000</pubDate>
		<dc:creator>Tea</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[snippit]]></category>

		<guid isPermaLink="false">http://www.wirelust.com/?p=326</guid>
		<description><![CDATA[Working on a Flash project.  I had to use the microphone to record some audio and generate a simple waveform so the user has some feedback that they are being heard.  While not a true waveform, you can use the microphone activity level to generate something that works pretty well. ]]></description>
			<content:encoded><![CDATA[<p>Working on a Flash project.  I had to use the microphone to record some audio and generate a simple waveform so the user has some feedback that they are being heard.  While not a true waveform, you can use the microphone activity level to generate something that works pretty well. </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_waveform_1461204194"
			class="flashmovie"
			width="500"
			height="250">
	<param name="movie" value="http://www.wirelust.com/examples/waveform/bin-debug/waveform.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.wirelust.com/examples/waveform/bin-debug/waveform.swf"
			name="fm_waveform_1461204194"
			width="500"
			height="250">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here is the code to generate the above sample:<br />
<pre class="actionscript"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">wirelust</span>.<span style="color: #006600;">waveform</span>.<span style="color: #006600;">Waveform</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">media</span>.<span style="color: #0066CC;">Microphone</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> wave:Waveform = <span style="color: #000000; font-weight: bold;">new</span> Waveform<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> mic:<span style="color: #0066CC;">Microphone</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	wave.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">50</span>;
	wave.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">450</span>;
	wave.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span> - wave.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span>;
	wave.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span> - wave.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span>;
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>wave<span style="color: #66cc66;">&#41;</span>;
	
	mic = <span style="color: #0066CC;">Microphone</span>.<span style="color: #006600;">getMicrophone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	mic.<span style="color: #0066CC;">setUseEchoSuppression</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
	
	<span style="color: #808080; font-style: italic;">// loopback is required so we can get the activity level and create the waveform. - so stupid</span>
	mic.<span style="color: #006600;">setLoopBack</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
	
	<span style="color: #808080; font-style: italic;">// turn off the volume for the loopback</span>
	<span style="color: #000000; font-weight: bold;">var</span> mySoundTransform:SoundTransform = <span style="color: #000000; font-weight: bold;">new</span> SoundTransform<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	mySoundTransform.<span style="color: #006600;">volume</span> = <span style="color: #cc66cc;">0</span>;
	mic.<span style="color: #006600;">soundTransform</span> = mySoundTransform;
	
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, onFrameEnter<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onFrameEnter<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>mic != <span style="color: #000000; font-weight: bold;">null</span> &amp;&amp; !mic.<span style="color: #0066CC;">muted</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		wave.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span>mic.<span style="color: #0066CC;">activityLevel</span><span style="color: #66cc66;">&#41;</span>;
		wave.<span style="color: #006600;">invalidateDisplayList</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></p>
<p>And for the Waform class:<br />
<pre class="actionscript"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">*</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">*</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Matrix</span>;
&nbsp;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">*</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">IFill</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">IStroke</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">SolidColor</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">Stroke</span>;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Waveform <span style="color: #0066CC;">extends</span> UIComponent <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> levels:<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: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">color</span>:uint = 0x000000;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">borderColor</span>:uint = 0xCCCCCC;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> borderWidth:uint = <span style="color: #cc66cc;">1</span>;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> autoScale:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">true</span>;
	
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Waveform<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#125;</span>
	
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">level</span>:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// trim the levels so we don't keep eating up memory</span>
		<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>levels.<span style="color: #0066CC;">length</span> &gt; <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			levels.<span style="color: #006600;">shift</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		levels.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">level</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	
	override protected <span style="color: #000000; font-weight: bold;">function</span> updateDisplayList<span style="color: #66cc66;">&#40;</span>param1:<span style="color: #0066CC;">Number</span>, param2:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> scaleFactor:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1</span>;
		<span style="color: #808080; font-style: italic;">// autoscale will find the highest volume and scale all lines in the display accordingly.</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>autoScale<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> highestLevel:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
			<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:uint=<span style="color: #cc66cc;">0</span>; i&lt;levels.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>levels<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> &gt; highestLevel<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					highestLevel = levels<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span>
			scaleFactor = <span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span>/highestLevel;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">super</span>.<span style="color: #006600;">updateDisplayList</span><span style="color: #66cc66;">&#40;</span>param1, param2<span style="color: #66cc66;">&#41;</span>;
		graphics.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		graphics.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #0066CC;">color</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #000000; font-weight: bold;">true</span>, LineScaleMode.<span style="color: #006600;">NORMAL</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #000000; font-weight: bold;">var</span> lineX:uint = <span style="color: #cc66cc;">0</span>;
		<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> j:uint=<span style="color: #cc66cc;">0</span>; j&lt;levels.<span style="color: #0066CC;">length</span>; j++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			graphics.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>lineX, <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span> - <span style="color: #66cc66;">&#40;</span>levels<span style="color: #66cc66;">&#91;</span>j<span style="color: #66cc66;">&#93;</span> * scaleFactor<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			graphics.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>lineX, <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span> + <span style="color: #66cc66;">&#40;</span>levels<span style="color: #66cc66;">&#91;</span>j<span style="color: #66cc66;">&#93;</span> * scaleFactor<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			lineX++;
		<span style="color: #66cc66;">&#125;</span>
		
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>borderWidth &gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			graphics.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span>borderWidth, <span style="color: #0066CC;">borderColor</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #000000; font-weight: bold;">true</span>, LineScaleMode.<span style="color: #006600;">NORMAL</span><span style="color: #66cc66;">&#41;</span>;
			graphics.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></p>
<h3>Files</h3>
<p><a href="http://www.wirelust.com/examples/waveform/waveform.zip"><img src="http://www.wirelust.com/img/famfamicons/icons/page_white_put.png" border="0"></a>&nbsp;<a href="http://www.wirelust.com/examples/waveform/waveform.zip">Download source code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wirelust.com/2009/12/08/snippit-generating-a-faux-waveform-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 port of JZLib</title>
		<link>http://www.wirelust.com/2009/06/08/as3-port-of-jzlib/</link>
		<comments>http://www.wirelust.com/2009/06/08/as3-port-of-jzlib/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 15:00:33 +0000</pubDate>
		<dc:creator>Tea</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[fzip]]></category>
		<category><![CDATA[zlib]]></category>

		<guid isPermaLink="false">http://www.wirelust.com/?p=223</guid>
		<description><![CDATA[One tricky thing about FZip is that when running in Flash Player it requires your zip files to have an adler32 checksum for each file in order to work.  This is normally fixed with a work around python script provided with FZip.   

The python script is easy and all, but why not figure out how to do it in pure AS3 with more standard zip files?]]></description>
			<content:encoded><![CDATA[<p>Last month I was working on a project that used <a href="http://codeazur.com.br/lab/fzip/" target="_blank">FZip</a> to decompress some zip files in flash.</p>
<p>One tricky thing about FZip is that when running in Flash Player it requires your zip files to have an adler32 checksum for each file in order to work.  This is normally fixed with a work around python script provided with FZip.   </p>
<p>The python script is easy and all, but why not figure out how to do it in pure AS3 with more standard zip files?</p>
<p>The checksum is needed because AS3&#8242;s ByteArray only supports ZLib when running in Flash Player.  In AIR it supports deflate which is what zip files use by default.  I would be really curious to hear from Adobe why they chose not to support deflate since you need deflate for Zlib to work anyway.</p>
<p>I decided to implement inflate in as3 but I didn&#8217;t want to do it with new code so I looked for FOSS projects to port.  <a href="http://www.jcraft.com/jzlib/" target="_blank">JZlib</a> was a good choice because Java is similar to AS3 and it didn&#8217;t rely on any external system calls.</p>
<p>This port supports everything in JZlib so you can use it for any inflate or deflate operations you might need.  </p>
<h3>To use with FZip</h3>
<p>I used this library in FZip so it no longer requires that zip files be converted before use.  It is tested to be working with the OSX cli zip command.  It doesn&#8217;t work with OSX finder zip compression because of another issue.</b></p>
<ul>
<li><a href="/examples/fzip_as3zlib/fzip_snapshot_20100209.zip">Download Modified FZip Source</a></li>
<li><a href="/examples/fzip_as3zlib/as3zlib_snapshot_20100303.zip">Download as3zlib</a></li>
<li><a href="http://code.google.com/p/as3zlib/" target="_blank">Google Code Home for as3zlib</a></li>
<li><a href="/examples/fzip_as3zlib/fzip.html" target="_blank">View FZip decompress example</a></li>
</ul>
<p><strong>In FZipFile.as:</strong><br />
<pre class="actionscript">protected <span style="color: #000000; font-weight: bold;">function</span> parseContent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>:IDataInput<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_compressionMethod === COMPRESSION_DEFLATED &amp;&amp; !_encrypted<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>HAS_INFLATE<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Adobe Air supports inflate decompression.</span>
			<span style="color: #808080; font-style: italic;">// If we got here, this is an Air application</span>
			<span style="color: #808080; font-style: italic;">// and we can decompress without using the Adler32 hack</span>
			<span style="color: #808080; font-style: italic;">// so we just write out the raw deflate compressed file</span>
			<span style="color: #0066CC;">data</span>.<span style="color: #006600;">readBytes</span><span style="color: #66cc66;">&#40;</span>_content, <span style="color: #cc66cc;">0</span>, _sizeCompressed<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_hasAdler32<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// Add zlib header</span>
			<span style="color: #808080; font-style: italic;">// CMF (compression method and info)</span>
			_content.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>0x78<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// FLG (compression level, preset dict, checkbits)</span>
			<span style="color: #000000; font-weight: bold;">var</span> flg:uint = <span style="color: #66cc66;">&#40;</span>~_deflateSpeedOption &lt;&lt; <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span> &amp; 0xc0;
			flg += <span style="color: #cc66cc;">31</span> - <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>0x78 &lt;&lt; <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span> | flg<span style="color: #66cc66;">&#41;</span> % <span style="color: #cc66cc;">31</span><span style="color: #66cc66;">&#41;</span>;
			_content.<span style="color: #006600;">writeByte</span><span style="color: #66cc66;">&#40;</span>flg<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// Add raw deflate-compressed file</span>
			<span style="color: #0066CC;">data</span>.<span style="color: #006600;">readBytes</span><span style="color: #66cc66;">&#40;</span>_content, <span style="color: #cc66cc;">2</span>, _sizeCompressed<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// Add adler32 checksum</span>
			_content.<span style="color: #0066CC;">position</span> = _content.<span style="color: #0066CC;">length</span>;
			_content.<span style="color: #006600;">writeUnsignedInt</span><span style="color: #66cc66;">&#40;</span>_adler32<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">data</span>.<span style="color: #006600;">readBytes</span><span style="color: #66cc66;">&#40;</span>_content, <span style="color: #cc66cc;">0</span>, _sizeCompressed<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">//throw new Error(&quot;Adler32 checksum not found.&quot;);</span>
		<span style="color: #66cc66;">&#125;</span>
		isCompressed = <span style="color: #000000; font-weight: bold;">true</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_compressionMethod == COMPRESSION_NONE<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">data</span>.<span style="color: #006600;">readBytes</span><span style="color: #66cc66;">&#40;</span>_content, <span style="color: #cc66cc;">0</span>, _sizeCompressed<span style="color: #66cc66;">&#41;</span>;
		isCompressed = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Compression method &quot;</span> + _compressionMethod + <span style="color: #ff0000;">&quot; is not supported.&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	_content.<span style="color: #0066CC;">position</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
protected <span style="color: #000000; font-weight: bold;">function</span> uncompress<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>isCompressed &amp;&amp; _content.<span style="color: #0066CC;">length</span> &gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		_content.<span style="color: #0066CC;">position</span> = <span style="color: #cc66cc;">0</span>;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>HAS_INFLATE<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			_content.<span style="color: #006600;">uncompress</span>.<span style="color: #0066CC;">apply</span><span style="color: #66cc66;">&#40;</span>_content, <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;deflate&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>_hasAdler32<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			_content.<span style="color: #006600;">uncompress</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> uncompr:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> d_stream:ZStream=<span style="color: #000000; font-weight: bold;">new</span> ZStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			d_stream.<span style="color: #006600;">next_in</span> = _content;
			d_stream.<span style="color: #006600;">next_in_index</span> = <span style="color: #cc66cc;">0</span>;
			d_stream.<span style="color: #006600;">next_out</span> = uncompr;
			d_stream.<span style="color: #006600;">next_out_index</span> = <span style="color: #cc66cc;">0</span>;
			
			<span style="color: #000000; font-weight: bold;">var</span> err:<span style="color: #0066CC;">int</span> = d_stream.<span style="color: #006600;">inflateInitWithNoWrap</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>d_stream.<span style="color: #006600;">total_in</span> &lt;= _content.<span style="color: #0066CC;">length</span> &amp;&amp; i&lt;=_content.<span style="color: #0066CC;">length</span>*<span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				d_stream.<span style="color: #006600;">avail_in</span>=d_stream.<span style="color: #006600;">avail_out</span>=<span style="color: #cc66cc;">10</span>;
			
				err=d_stream.<span style="color: #006600;">inflate</span><span style="color: #66cc66;">&#40;</span>JZlib.<span style="color: #006600;">Z_NO_FLUSH</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>err == JZlib.<span style="color: #006600;">Z_STREAM_END</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #0066CC;">System</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;decompress success:&quot;</span> + <span style="color: #0066CC;">this</span>.<span style="color: #006600;">filename</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>err == JZlib.<span style="color: #006600;">Z_STREAM_ERROR</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #0066CC;">System</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;stream error:&quot;</span> + <span style="color: #0066CC;">this</span>.<span style="color: #006600;">filename</span> + <span style="color: #ff0000;">&quot; &quot;</span> + d_stream.<span style="color: #006600;">msg</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>err == JZlib.<span style="color: #006600;">Z_DATA_ERROR</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #0066CC;">System</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data error:&quot;</span> + <span style="color: #0066CC;">this</span>.<span style="color: #006600;">filename</span> + <span style="color: #ff0000;">&quot; &quot;</span> + d_stream.<span style="color: #006600;">msg</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">break</span>;
				<span style="color: #808080; font-style: italic;">//} else {</span>
				<span style="color: #808080; font-style: italic;">//	System.println(&quot;status:&quot; + this.filename + &quot; &quot; + err);</span>
				<span style="color: #66cc66;">&#125;</span>				
			<span style="color: #66cc66;">&#125;</span>
			err=d_stream.<span style="color: #006600;">inflateEnd</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_content = uncompr;			
		<span style="color: #66cc66;">&#125;</span>
		_content.<span style="color: #0066CC;">position</span> = <span style="color: #cc66cc;">0</span>;
		isCompressed = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></p>
<p><strong>*** UPDATE 2/9/2010:</strong> Thanks to Kathrin Furtlehner for sending me a test case for a bug where it wasn&#8217;t extracting the full file when dealing with longer strings.  I updated the patched FZip archive to reflect the fix.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wirelust.com/2009/06/08/as3-port-of-jzlib/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Converting binary to signed decimal in Actionscript</title>
		<link>http://www.wirelust.com/2009/04/08/converting-binary-to-signed-decimal-in-actionscript/</link>
		<comments>http://www.wirelust.com/2009/04/08/converting-binary-to-signed-decimal-in-actionscript/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 21:44:00 +0000</pubDate>
		<dc:creator>Tea</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[bitwise]]></category>

		<guid isPermaLink="false">http://www.wirelust.com/?p=157</guid>
		<description><![CDATA[If you&#8217;re like me, you may have been living these past few years taking advantage of the luxury of new sleek programming languages that rarely require you to do low level operations. One of the old skills I seem to always let get rusty enough is bitwise operation. Most code written with the help of [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re like me, you may have been living these past few years taking advantage of the luxury of new sleek programming languages that rarely require you to do low level operations.  One of the old skills I seem to always let get rusty enough is bitwise operation.  Most code written with the help of frameworks doesn&#8217;t require this type of code and most programmers probably don&#8217;t even bother to learn it anymore.</p>
<p>I came into an instance yesterday where I needed to do some bitwise work in actionscript.  The code was reading a bytestream from a binary file and converting to an array of numbers.  Since this project was ported from Java (by someone else), a simple operation was overlooked.  It was taking the binary number and converting it to a signed short.  Since actionscript doesn&#8217;t have the same casting mechanisms conversion isn&#8217;t as straight forward in java.</p>
<p>In java the operation looked like this:<br />
<pre class="java"><span style="color: #808080; font-style: italic;">//  binary: 1111 1111 1111 0001</span>
<span style="color: #993333;">int</span> hexValue = 0xFFF1;
&nbsp;
<span style="color: #993333;">short</span> value = <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">short</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>hexValue<span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// value = -15 </span></pre></p>
<p>Since short in java is always stored with a signed bit, the cast appropriately set the value at -15.</p>
<p>The way this was translated into Actionscript looked liked this:<br />
<pre class="actionscript"><span style="color: #808080; font-style: italic;">//  binary: 1111 1111 1111 0001</span>
<span style="color: #000000; font-weight: bold;">var</span> hexValue:<span style="color: #0066CC;">int</span> = 0xFFF1;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> value:<span style="color: #0066CC;">int</span> = <span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#40;</span>hexValue<span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// value = 65521  // Wrong! </span></pre></p>
<p>Actionscript has no concept of casting for primitives so the int(hexValue) doesn&#8217;t do anything at all.</p>
<p>Here is the workaround I came up with, I suspect there is a shorter way to get the same result but I can&#8217;t think of one right now.</p>
<p><pre class="actionscript"><span style="color: #808080; font-style: italic;">//  binary: 1111 1111 1111 0001</span>
<span style="color: #000000; font-weight: bold;">var</span> hexValue:<span style="color: #0066CC;">int</span> = 0xFFF1;
&nbsp;
<span style="color: #808080; font-style: italic;">// get everything except the signed bit &quot;111 1111 1111 0001&quot;</span>
<span style="color: #000000; font-weight: bold;">var</span> unsignedValue:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span>hexValue &amp; 0x7FFF<span style="color: #66cc66;">&#41;</span>;  
<span style="color: #808080; font-style: italic;">// unsignedValue now equals 32,753</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> signedValue:<span style="color: #0066CC;">Number</span> = unsignedValue;
&nbsp;
<span style="color: #808080; font-style: italic;">// if the signed flag is set, flip the value</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>hexValue &gt;&gt; <span style="color: #cc66cc;">15</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    signedValue = unsignedValue - 0x8000;   <span style="color: #808080; font-style: italic;">// 0x800 =  32,768 (maximum 15 bit number)</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// signedValue = -15 </span></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wirelust.com/2009/04/08/converting-binary-to-signed-decimal-in-actionscript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Font Reader</title>
		<link>http://www.wirelust.com/2009/04/02/font-reader/</link>
		<comments>http://www.wirelust.com/2009/04/02/font-reader/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 09:38:22 +0000</pubDate>
		<dc:creator>Tea</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://www.wirelust.com/?p=143</guid>
		<description><![CDATA[I&#8217;ve been doing some work with Five3D lately. I extended it so I could render text with proper kerning pairs. I hit a bit of a wall though with converting my fonts to as3 since the way Mathieu does it doesn&#8217;t lend itself well to getting kerning pairs from flash itself. Looking for an alternative, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing some work with <a href="http://five3d.mathieu-badimon.com/" target="_blank">Five3D</a> lately.  I extended it so I could render text with proper kerning pairs.  I hit a bit of a wall though with converting my fonts to as3 since the way Mathieu does it doesn&#8217;t lend itself well to getting kerning pairs from flash itself.</p>
<p>Looking for an alternative, I started taking a look at <a href="http://www.sephiroth.it/weblog/archives/2007/07/fontreader_convert_truetype_fonts_in.php" target="_blank">Font Reader</a> which is a port of a project called <a href="https://typecast.dev.java.net/" target="_blank">Typecast</a> I saw a few years back. </p>
<p>Anyway. Long story short, I&#8217;ve been up all night playing around with and extending Font Reader (for my current project, but also because it&#8217;s fun to play with).</p>
<p>The version that is posted on the site uses a custom written path renderer which seems to have some bugs.  In particular it seems to clip at the end of a logical path segment.<br />
<img src="http://www.wirelust.com/img/entries/FontRenderer1.png" /></p>
<p>The custom objects were very close to the new stuff in the Flex 4 gumbo stuff from Adobe, so I was able to easily swap them out and use the Adobe classes instead.  Since that was so easy, I started working on getting editable point handles so I can start editing the paths within the application.  I have this about 75% done, but I can&#8217;t help quell that feeling that there must be a reusable class out there someone else wrote.  Anyone know of one?</p>
<p>Here&#8217;s a screen shot of my current working build for comparison:<br />
<img src="http://www.wirelust.com/img/entries/FontRenderer2.png" /></p>
<p>If I get this working by next week, I&#8217;ll post the code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wirelust.com/2009/04/02/font-reader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
