<?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>Justin Imhoff</title>
	<atom:link href="http://justinimhoff.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://justinimhoff.com</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 14:24:31 +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>AIRKinect Extension v1 Live</title>
		<link>http://justinimhoff.com/airkinect-extension-v1-live/</link>
		<comments>http://justinimhoff.com/airkinect-extension-v1-live/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 23:46:20 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=250</guid>
		<description><![CDATA[Check out the AIRKinect Extension version 1. It has taken a lot of work for everyone to learn C++ and what it takes to make a native extension, but its out and ready to be pushed to the limits. Thanks for all the hard work as3NUI guys, especially Ross Gerbasi! Check it out - http://www.as3nui.com/air-kinect/]]></description>
			<content:encoded><![CDATA[<p>Check out the AIRKinect Extension version 1. It has taken a lot of work for everyone to learn C++ and what it takes to make a native extension, but its out and ready to be pushed to the limits. Thanks for all the hard work as3NUI guys, especially Ross Gerbasi!</p>
<p>Check it out - <a href="http://www.as3nui.com/air-kinect/">http://www.as3nui.com/air-kinect/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/airkinect-extension-v1-live/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AIR Extensions</title>
		<link>http://justinimhoff.com/air-extensions/</link>
		<comments>http://justinimhoff.com/air-extensions/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 15:58:56 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=241</guid>
		<description><![CDATA[My life for the next Month: &#60;extension xmlns=&#34;http://ns.adobe.com/air/extension/2.5&#34;&#62; &#60;name&#62;Microsoft Kinect Extension for ActionScript&#60;/name&#62; &#60;copyright&#62;Copyright 2011, NUIORITY.&#60;/copyright&#62; &#60;id&#62;com.justinimhoff.kinect.extensions.KinectExtension&#60;/id&#62; &#60;versionNumber&#62;1&#60;/versionNumber&#62; &#60;platforms&#62; &#60;platform name=&#34;Windows-x86&#34;&#62; &#60;applicationDeployment&#62; &#60;nativeLibrary&#62;KinectExtension.dll&#60;/nativeLibrary&#62; &#60;initializer&#62;ExtensionInitializer&#60;/initializer&#62; &#60;finalizer&#62;ExtensionFinalizer&#60;/finalizer&#62; &#60;/applicationDeployment&#62; &#60;/platform&#62; &#60;/platforms&#62; &#60;/extension&#62;]]></description>
			<content:encoded><![CDATA[<p>My life for the next Month:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>extension xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://ns.adobe.com/air/extension/2.5&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>name<span style="color: #339933;">&gt;</span>Microsoft Kinect Extension <span style="color: #000000; font-weight: bold;">for</span> ActionScript<span style="color: #339933;">&lt;/</span>name<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>copyright<span style="color: #339933;">&gt;</span>Copyright <span style="color: #cc66cc;">2011</span>, NUIORITY.<span style="color: #339933;">&lt;/</span>copyright<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>id<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">justinimhoff</span>.<span style="color: #006633;">kinect</span>.<span style="color: #006633;">extensions</span>.<span style="color: #006633;">KinectExtension</span><span style="color: #339933;">&lt;/</span>id<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>versionNumber<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;/</span>versionNumber<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>platforms<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>platform name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Windows-x86&quot;</span><span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>applicationDeployment<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>nativeLibrary<span style="color: #339933;">&gt;</span>KinectExtension.<span style="color: #006633;">dll</span><span style="color: #339933;">&lt;/</span>nativeLibrary<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>initializer<span style="color: #339933;">&gt;</span>ExtensionInitializer<span style="color: #339933;">&lt;/</span>initializer<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>finalizer<span style="color: #339933;">&gt;</span>ExtensionFinalizer<span style="color: #339933;">&lt;/</span>finalizer<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;/</span>applicationDeployment<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>platform<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>platforms<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>extension<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/air-extensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Image Uploader</title>
		<link>http://justinimhoff.com/flex-image-uploader/</link>
		<comments>http://justinimhoff.com/flex-image-uploader/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 17:03:57 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=229</guid>
		<description><![CDATA[Basic utility that allows the ability to open an image and re-size that image to a specific width or you can use height. Then when requesting the image for an mx:image component it will always be in a png because it takes an internal snapshot. This helps for not saving transparency, reduce file size, protecting [...]]]></description>
			<content:encoded><![CDATA[<p>Basic utility that allows the ability to open an image and re-size that image to a specific width or you can use height. Then when requesting the image for an mx:image component it will always be in a png because it takes an internal snapshot. This helps for not saving transparency, reduce file size, protecting against image code embedding, and also allows saving consistent byte array to db if so wanted. <br/><br/></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.justinimhoff.library.managers</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.display.Loader</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.events.Event</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.events.EventDispatcher</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.net.FileFilter</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.net.FileReference</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.utils.ByteArray</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.graphics.ImageSnapshot</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.graphics.codec.PNGEncoder</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Dispatched when the user has picked and image and it is has processed and resized
     */</span>
    <span style="color: #009900;">&#91;</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;imageReady&quot;</span>, type <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;flash.events.Event&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Class that can upload an image and directly sets information and scale to
     * resize an image. When returning an image returns a snap shot where the data
     * can be used to set an iimage source and file information can be used for the
     * server
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ImageUploader <span style="color: #000000; font-weight: bold;">extends</span> EventDispatcher
    <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">const</span> IMAGE_READY_EVENT<span style="color: #339933;">:</span><span style="color: #003399;">String</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'imageReady'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> var _image<span style="color: #339933;">:</span>SmoothImage<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> var _resizeHeight<span style="color: #339933;">:</span><span style="color: #003399;">Number</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> var fileRef<span style="color: #339933;">:</span>FileReference<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> var fileTypes<span style="color: #339933;">:</span><span style="color: #003399;">Array</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Call contructor
         * @param image Takes a SmoothImage component that is best used when resizing
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function ImageUploader<span style="color: #009900;">&#40;</span>image<span style="color: #339933;">:</span>SmoothImage<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            onConstructor<span style="color: #009900;">&#40;</span>image<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Displays a pop for the user to select the file they want to upload
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function browse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            fileRef.<span style="color: #006633;">browse</span><span style="color: #009900;">&#40;</span>fileTypes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function get resizeHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Number</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> _resizeHeight<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Sets the width used to calculate the height and width of the thumbnail from
         * the original
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function set resizeHeight<span style="color: #009900;">&#40;</span>value<span style="color: #339933;">:</span><span style="color: #003399;">Number</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            _resizeHeight <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Returns a snapshot to access data and file type for the encoder
         * that was used - default to png
         * @return
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function get image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>ByteArray
        <span style="color: #009900;">&#123;</span>
            var pngEnco<span style="color: #339933;">:</span>PNGEncoder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PNGEncoder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            var imageSnapshot<span style="color: #339933;">:</span>ImageSnapshot <span style="color: #339933;">=</span> ImageSnapshot.<span style="color: #006633;">captureImage</span><span style="color: #009900;">&#40;</span>_image, <span style="color: #cc66cc;">0</span>, pngEnco<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> imageSnapshot.<span style="color: #006633;">data</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #008000; font-style: italic; font-weight: bold;">/**
		 * 
		 * 
		 */</span>		
        <span style="color: #000000; font-weight: bold;">public</span> function removeImage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            _image.<span style="color: #006633;">source</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
            _image.<span style="color: #006633;">width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            _image.<span style="color: #006633;">height</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Initialize and set listners and define available types allowed.
         * Only support jpg and png images
         */</span>
        <span style="color: #000000; font-weight: bold;">protected</span> function onConstructor<span style="color: #009900;">&#40;</span>image<span style="color: #339933;">:</span>SmoothImage<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//Setup file reference</span>
            fileRef <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            fileRef.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Event</span>.<span style="color: #006633;">SELECT</span>, onFileSelect<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            fileRef.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Event</span>.<span style="color: #006633;">COMPLETE</span>, onFileLoadComplete<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//create filter</span>
            fileTypes <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileFilter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Images&quot;</span>, <span style="color: #0000ff;">&quot;*.jpeg;*.jpg;*.png&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//Set image</span>
            _image <span style="color: #339933;">=</span> image<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Load the image for local manipulation
         * @param evt
         */</span>
        <span style="color: #000000; font-weight: bold;">protected</span> function onFileSelect<span style="color: #009900;">&#40;</span>evt<span style="color: #339933;">:</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            fileRef.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Load the full image in order to access the height and width of
         * the original image
         * @param evt
         */</span>
        <span style="color: #000000; font-weight: bold;">protected</span> function onFileLoadComplete<span style="color: #009900;">&#40;</span>evt<span style="color: #339933;">:</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//Get size</span>
            var ldr<span style="color: #339933;">:</span>Loader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            ldr.<span style="color: #006633;">contentLoaderInfo</span>.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Event</span>.<span style="color: #006633;">COMPLETE</span>, onLoadImageComplete<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            ldr.<span style="color: #006633;">loadBytes</span><span style="color: #009900;">&#40;</span>fileRef.<span style="color: #006633;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Resize the image directly to create the thumbnail. Uses width only and
         * calculates the height based on the ratio. Sets the source on the image and sets
         * the new width and height
         * @param evt
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">protected</span> function onLoadImageComplete<span style="color: #009900;">&#40;</span>evt<span style="color: #339933;">:</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            var h<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> resizeHeight<span style="color: #339933;">;</span>
            var ratio<span style="color: #339933;">:</span><span style="color: #003399;">Number</span> <span style="color: #339933;">=</span> h <span style="color: #339933;">/</span> evt.<span style="color: #006633;">currentTarget</span>.<span style="color: #006633;">height</span><span style="color: #339933;">;</span>
            var w<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> evt.<span style="color: #006633;">currentTarget</span>.<span style="color: #006633;">width</span> <span style="color: #339933;">*</span> ratio<span style="color: #339933;">;</span>
            _image.<span style="color: #006633;">height</span> <span style="color: #339933;">=</span> h<span style="color: #339933;">;</span>
            _image.<span style="color: #006633;">width</span> <span style="color: #339933;">=</span> w<span style="color: #339933;">;</span>
            _image.<span style="color: #006633;">source</span> <span style="color: #339933;">=</span> fileRef.<span style="color: #006633;">data</span><span style="color: #339933;">;</span>
            dispatchEvent<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Event</span><span style="color: #009900;">&#40;</span>IMAGE_READY_EVENT, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The smooth image is used for re-sized images and just helps when taking a snapshot. <br/><br/></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.justinimhoff.library.managers</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.display.Bitmap</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.display.Loader</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.events.Event</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.controls.Image</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.core.mx_internal</span><span style="color: #339933;">;</span>
&nbsp;
    use namespace mx_internal<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Image component used for resizing. Available in spark, but not in mx.
     * TODO - use spark image
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SmoothImage <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Image</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> function SmoothImage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			onConstructor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">protected</span> function onConstructor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#123;</span>
			cacheAsBitmap <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		override <span style="color: #000000; font-weight: bold;">public</span> function set source<span style="color: #009900;">&#40;</span>value<span style="color: #339933;">:</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>value <span style="color: #339933;">!=</span> source<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">source</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Turn on smoothing as a default
         * @private
         */</span>
        mx_internal override function contentLoaderInfo_completeEventHandler<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            var smoothLoader<span style="color: #339933;">:</span>Loader <span style="color: #339933;">=</span> event.<span style="color: #006633;">target</span>.<span style="color: #006633;">loader</span> as Loader<span style="color: #339933;">;</span>
            var smoothImage<span style="color: #339933;">:</span>Bitmap <span style="color: #339933;">=</span> smoothLoader.<span style="color: #006633;">content</span> as Bitmap<span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>smoothImage<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                smoothImage.<span style="color: #006633;">smoothing</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">contentLoaderInfo_completeEventHandler</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/flex-image-uploader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data Management Utility</title>
		<link>http://justinimhoff.com/data-management-utilit/</link>
		<comments>http://justinimhoff.com/data-management-utilit/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 16:49:53 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=222</guid>
		<description><![CDATA[This is a management class I like to use in enterprise applications to manipulate common data. It is usually a good design if using BlazeDS to turn on legacy collections so collections will be returned as an Array instead of an ArrayCollection. This will minimize processing and unless you are binding directly to the result, [...]]]></description>
			<content:encoded><![CDATA[<p>This is a management class I like to use in enterprise applications to manipulate common data. It is usually a good design if using BlazeDS to turn on legacy collections so collections will be returned as an Array instead of an ArrayCollection. This will minimize processing and  unless you are binding directly to the result, there is no reason to use an ArrayCollection that is dispatching events. These methods help in memory and performance management.<br />
<br/></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.justinimhoff.library.managers</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.net.ObjectEncoding</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.net.registerClassAlias</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.utils.ByteArray</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.utils.describeType</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.collections.ArrayCollection</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.collections.ListCollectionView</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.collections.Sort</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.collections.SortField</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">mx.utils.ObjectUtil</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     *
     *  The DataCollectionManager class is a utility class that allows for the management of
     *  Array, ArrayCollection, and Object. In cases where items need to be copied or cloned from multiple
     *  items, it is better to use this class because it impliments best practices for looping
     *  and event management.
     *
     * @see mx.collections.ArrayCollection
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DataCollectionManager <span style="color: #000000; font-weight: bold;">extends</span> Singleton
    <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Copies objects from one array to another and is left to the user to manage refresh or events if using source of ArrayCollection.
         *
         * @param sourceCollection The collection of all the inforamation that needs to be copied
         * @param targetCollection The collection to add to
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function copyItemsToCollection<span style="color: #009900;">&#40;</span>sourceCollection<span style="color: #339933;">:</span><span style="color: #003399;">Array</span>, targetCollection<span style="color: #339933;">:</span><span style="color: #003399;">Array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            var i<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            var len<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> sourceCollection.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                targetCollection.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span>sourceCollection<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Removes objects from a targeted collection. The items must be of the same object memory allocation
         *
         * @param itemsToRemove The Array of items to be removed
         * @param targetCollection The collection of where the items reside
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function removeItemsFromCollection<span style="color: #009900;">&#40;</span>itemsToRemove<span style="color: #339933;">:</span><span style="color: #003399;">Array</span>, targetCollection<span style="color: #339933;">:</span><span style="color: #003399;">Array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            var i<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            var len<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> itemsToRemove.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
            var itemIndex<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                itemIndex <span style="color: #339933;">=</span> targetCollection.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span>itemsToRemove<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>itemIndex <span style="color: #339933;">&lt;</span> targetCollection.<span style="color: #006633;">length</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    targetCollection.<span style="color: #006633;">splice</span><span style="color: #009900;">&#40;</span>itemIndex, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Clones source of an ArrayCollection or Array into a target collection and manages the event lifecycle by dispatching one update.
         *
         * @param sourceCollection The collection of all the inforamation that needs to be copied
         * @param targetCollection The collection to add to
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function cloneArrayToArrayCollection<span style="color: #009900;">&#40;</span>sourceCollection<span style="color: #339933;">:</span><span style="color: #003399;">Array</span>, targetCollection<span style="color: #339933;">:</span>ArrayCollection<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            targetCollection.<span style="color: #006633;">disableAutoUpdate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            targetCollection.<span style="color: #006633;">removeAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            targetCollection.<span style="color: #006633;">source</span> <span style="color: #339933;">=</span> sourceCollection<span style="color: #339933;">;</span>
            targetCollection.<span style="color: #006633;">enableAutoUpdate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            targetCollection.<span style="color: #006633;">refresh</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Clones source of an ArrayCollection or Array into a target collection and cast the object by the provided type.
         * Also manages the event lifecycle by dispatching one update.
         *
         * @param sourceCollection The collection of all the inforamation that needs to be copied
         * @param targetCollection The collection to add to
         * @param classType The class to case each object as
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function cloneArrayToArrayCollectionClassType<span style="color: #009900;">&#40;</span>sourceCollection<span style="color: #339933;">:</span><span style="color: #003399;">Array</span>, targetCollection<span style="color: #339933;">:</span>ArrayCollection, classType<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">Class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            targetCollection.<span style="color: #006633;">disableAutoUpdate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            targetCollection.<span style="color: #006633;">removeAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            var i<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            var len<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> sourceCollection.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">try</span>
                <span style="color: #009900;">&#123;</span>
                    targetCollection.<span style="color: #006633;">addItem</span><span style="color: #009900;">&#40;</span>sourceCollection<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> as classType<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>err<span style="color: #339933;">:</span><span style="color: #003399;">Error</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    trace<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'An error has occured in casting the object: '</span> <span style="color: #339933;">+</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>err.<span style="color: #006633;">message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            targetCollection.<span style="color: #006633;">enableAutoUpdate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            targetCollection.<span style="color: #006633;">refresh</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Converts a vector object to array for easy handling and also for instances where
         * switchng between mxml and spark components selected items.
         *
         * @param v The vector to copy into an Array
         * @return An array of items that where part of the vector
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function convertVectorToArray<span style="color: #009900;">&#40;</span>vector<span style="color: #339933;">:</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Array</span>
        <span style="color: #009900;">&#123;</span>
            var vec<span style="color: #339933;">:</span><span style="color: #003399;">Vector</span>.<span style="color: #339933;">&lt;</span>Object<span style="color: #339933;">&gt;</span> <span style="color: #339933;">=</span> <span style="color: #003399;">Vector</span>.<span style="color: #339933;">&lt;</span>Object<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>vector<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            var arr<span style="color: #339933;">:</span><span style="color: #003399;">Array</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span> each <span style="color: #009900;">&#40;</span>var i<span style="color: #339933;">:</span><span style="color: #003399;">Object</span> in vec<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                arr.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">return</span> arr<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Recurively flatten nested objects and keep the property identifier and value of the property
         *
         * @param source The object that has information to copy
         * @param pushTo The clean object to push properties and value into
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function pushToFlatObject<span style="color: #009900;">&#40;</span>source<span style="color: #339933;">:</span><span style="color: #003399;">Object</span>, pushTo<span style="color: #339933;">:</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            var objectInfo<span style="color: #339933;">:</span><span style="color: #003399;">Object</span><span style="color: #339933;">;</span>
            var i<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #339933;">;</span>
            var len<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span> each <span style="color: #009900;">&#40;</span>var item<span style="color: #339933;">:*</span> in source<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ObjectUtil.<span style="color: #006633;">isSimple</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    objectInfo <span style="color: #339933;">=</span> ObjectUtil.<span style="color: #006633;">getClassInfo</span><span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                    len <span style="color: #339933;">=</span> objectInfo.<span style="color: #006633;">properties</span>.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
                    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        <span style="color: #666666; font-style: italic;">//Show the name and the value </span>
                        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#91;</span>objectInfo.<span style="color: #006633;">properties</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">localName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> item<span style="color: #009900;">&#41;</span>
                        <span style="color: #009900;">&#123;</span>
                            pushTo<span style="color: #009900;">&#91;</span>objectInfo.<span style="color: #006633;">properties</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">localName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> item<span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    pushToFlatObject<span style="color: #009900;">&#40;</span>item, pushTo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Converts a plain object to be an instance of the class
         * passed as the second variable.  This is not a recursive funtion
         * and will only work for the first level of nesting.  When you have
         * deeply nested objects, you first need to convert the nested
         * objects to class instances, and then convert the top level object.
         *
         * @param object The plain object that should be converted
         * @param clazz The type to convert the object to
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function objectToInstance<span style="color: #009900;">&#40;</span>object<span style="color: #339933;">:</span><span style="color: #003399;">Object</span>, clazz<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">Class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:*</span>
        <span style="color: #009900;">&#123;</span>
            var bytes<span style="color: #339933;">:</span>ByteArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            bytes.<span style="color: #006633;">objectEncoding</span> <span style="color: #339933;">=</span> ObjectEncoding.<span style="color: #006633;">AMF0</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Write out the bytes of the original object</span>
            var objBytes<span style="color: #339933;">:</span>ByteArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            objBytes.<span style="color: #006633;">objectEncoding</span> <span style="color: #339933;">=</span> ObjectEncoding.<span style="color: #006633;">AMF0</span><span style="color: #339933;">;</span>
            objBytes.<span style="color: #006633;">writeObject</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Register all of the classes so they can be decoded via AMF</span>
            var typeInfo<span style="color: #339933;">:</span>XML <span style="color: #339933;">=</span> describeType<span style="color: #009900;">&#40;</span>clazz<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            var fullyQualifiedName<span style="color: #339933;">:</span><span style="color: #003399;">String</span> <span style="color: #339933;">=</span> typeInfo.@name.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">/::/</span>, <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            registerClassAlias<span style="color: #009900;">&#40;</span>fullyQualifiedName, clazz<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Write the new object information starting with the class information</span>
            var len<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> fullyQualifiedName.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
            bytes.<span style="color: #006633;">writeByte</span><span style="color: #009900;">&#40;</span>0x10<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 0x10 is AMF0 for &quot;typed object (class instance)&quot;</span>
            bytes.<span style="color: #006633;">writeUTF</span><span style="color: #009900;">&#40;</span>fullyQualifiedName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">// After the class name is set up, write the rest of the object</span>
            bytes.<span style="color: #006633;">writeBytes</span><span style="color: #009900;">&#40;</span>objBytes, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Read in the object with the class property added and return that</span>
            bytes.<span style="color: #006633;">position</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            var result<span style="color: #339933;">:*</span> <span style="color: #339933;">=</span> bytes.<span style="color: #006633;">readObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Copies properties from one object to another
         *
         * @param copyTo The object to copy to
         * @param copyFrom The object to copy from = the source
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function copyPropertiesToObject<span style="color: #009900;">&#40;</span>copyTo<span style="color: #339933;">:</span><span style="color: #003399;">Object</span>, copyFrom<span style="color: #339933;">:</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            var objectInfo<span style="color: #339933;">:</span><span style="color: #003399;">Object</span> <span style="color: #339933;">=</span> ObjectUtil.<span style="color: #006633;">getClassInfo</span><span style="color: #009900;">&#40;</span>copyFrom<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            var i<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            var len<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> objectInfo.<span style="color: #006633;">properties</span>.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//Show the name and the value </span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>copyTo.<span style="color: #006633;">hasOwnProperty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span> objectInfo.<span style="color: #006633;">properties</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">localName</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    copyTo<span style="color: #009900;">&#91;</span>objectInfo.<span style="color: #006633;">properties</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">localName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> copyFrom<span style="color: #009900;">&#91;</span>objectInfo.<span style="color: #006633;">properties</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">localName</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Allows the creation of multiple complex sorting for a provided collection. Provides the ability to customize the type of sort
         * and provides support for multiple sort fields.
         *
         * @param collection Supports Array and ListCollectionView.
         * @param sortItems An array of item identifiers to sort against, should be in an array of strings.
         * @param caseInsensitive When sorting strings, tells the comparitor whether to ignore the case of the values.
         * @param descending Tells the comparator whether to arrange items in descending order.
         * @param numeric Tells the comparitor whether to compare sort items as numbers, instead of alphabetically.
         *
         */</span>		
        <span style="color: #000000; font-weight: bold;">public</span> function createSort<span style="color: #009900;">&#40;</span>collection<span style="color: #339933;">:*</span>, sortItems<span style="color: #339933;">:</span><span style="color: #003399;">Array</span>,caseInsensitive<span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,descending<span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,numeric<span style="color: #339933;">:</span><span style="color: #003399;">Object</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#123;</span>
            var newSortField<span style="color: #339933;">:</span>SortField<span style="color: #339933;">;</span>
            var sortFieldList<span style="color: #339933;">:</span><span style="color: #003399;">Array</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #666666; font-style: italic;">//Create sort fields</span>
            <span style="color: #000000; font-weight: bold;">for</span> each<span style="color: #009900;">&#40;</span>var sortItem<span style="color: #339933;">:</span><span style="color: #003399;">String</span> in sortItems<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                newSortField <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SortField<span style="color: #009900;">&#40;</span>sortItem,caseInsensitive,descending,numeric<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                sortFieldList.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span>newSortField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #666666; font-style: italic;">//Create sort and assign to correct dataprovider</span>
            var collectionSort<span style="color: #339933;">:</span>Sort <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Sort<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            collectionSort.<span style="color: #006633;">fields</span> <span style="color: #339933;">=</span> sortFieldList<span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>collection is <span style="color: #003399;">Array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                collection.<span style="color: #006633;">sort</span> <span style="color: #339933;">=</span> collectionSort<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>collection is ListCollectionView<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                collection.<span style="color: #006633;">sort</span> <span style="color: #339933;">=</span> collectionSort<span style="color: #339933;">;</span>
                collection.<span style="color: #006633;">refresh</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/data-management-utilit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Staggered Event Dispatching</title>
		<link>http://justinimhoff.com/staggered-event-dispatching/</link>
		<comments>http://justinimhoff.com/staggered-event-dispatching/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 16:40:21 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=219</guid>
		<description><![CDATA[When using flex/flash and leveraging remote objects, there will be a time where you might need to dispatch two or more events simultaneous. The issue with this is when using BlazeDS you will run into a bundling effect of the events. The events will be fired in the same frame and as such they will [...]]]></description>
			<content:encoded><![CDATA[<p>When using flex/flash and leveraging remote objects, there will be a time where you might need to dispatch two or more events simultaneous. The issue with this is when using BlazeDS you will run into a bundling effect of the events. The events will be fired in the same frame and as such they will be considered as a bundled request. The down side is that one request will affect the time of return for the other request.<br/><br/><br />
<strong>Example:</strong> <br/><br />
Request 1 takes 135ms<br/><br />
Request 2 takes 784ms<br/><br />
These request will be processed as a bundle and will not be returned until both are performed so you will not benefit from performances tuned request and your result will be both returning in 919ms and your UI will have to process both pieces of information together instead of staggering layout. <br/><br />
The alternative is to make sure each event is dispatched in a separate frame so there is no bundling. <br/></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.justinimhoff.library.utilities</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.events.EventDispatcher</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.events.TimerEvent</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.utils.Timer</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     *
     * Creates a queue of events that only one is dispatched every other key frame in order to
     * get away from bundling of events from the player an browser. When bundling of events occurs,
     * the slowest running will impac the result time of all others and items live on a single thread
     * server side.
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StaggeredRemoteDispatcher <span style="color: #000000; font-weight: bold;">extends</span> EventDispatcher
    <span style="color: #009900;">&#123;</span>
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * set to low value so it will only dispatch on next keyframe
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> var dispatchTimer<span style="color: #339933;">:</span><span style="color: #003399;">Timer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Timer</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * a queue of events to dispatch
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> var events<span style="color: #339933;">:</span><span style="color: #003399;">Array</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Adds an event to the queue that will be called on the next frame event.
         * Starts the time and adds event listner for the next interval
         * @param event
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function addFunction<span style="color: #009900;">&#40;</span>item<span style="color: #339933;">:</span>Function<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>events.<span style="color: #006633;">length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                dispatchTimer.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span>TimerEvent.<span style="color: #006633;">TIMER</span>, dispatchSequenceEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                dispatchTimer.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            events.<span style="color: #006633;">push</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Dispatches the next event in the queue and stops the timer and removes the event
         * listner if there are no more items.
         * @param event
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">protected</span> function dispatchSequenceEvent<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span>TimerEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>events.<span style="color: #006633;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                var callFunction<span style="color: #339933;">:</span>Function <span style="color: #339933;">=</span> events<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> as Function<span style="color: #339933;">;</span>
                callFunction.<span style="color: #006633;">call</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//remove just called function</span>
		events.<span style="color: #006633;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>events.<span style="color: #006633;">length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				dispatchTimer.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				dispatchTimer.<span style="color: #006633;">removeEventListener</span><span style="color: #009900;">&#40;</span>TimerEvent.<span style="color: #006633;">TIMER</span>, dispatchSequenceEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/staggered-event-dispatching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Favorite Singleton Manager</title>
		<link>http://justinimhoff.com/favorite-singleton-manager/</link>
		<comments>http://justinimhoff.com/favorite-singleton-manager/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 23:32:22 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=205</guid>
		<description><![CDATA[I use this as the core Singleton management class in most enterprise applications. To use, make sure your new class extends Singleton and then in the view grab a instance of a Singleton management class. Extending the Singleton class allows leveraging event dispatching as if you extended the event dispatcher, but through the Singleton class [...]]]></description>
			<content:encoded><![CDATA[<p>I use this as the core Singleton management class in most enterprise applications. To use, make sure your new class extends Singleton and then in the view grab a instance of a Singleton management class. Extending the Singleton class allows leveraging event dispatching as if you extended the event dispatcher, but through the Singleton class you can manage the memory of Singletons by removing if not in use. This is a simple core class to use and leverage in your enterprise application.<br />
<br/></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"> var viewManager<span style="color: #339933;">:</span>ViewManager <span style="color: #339933;">=</span> Singleton.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>ViewManager<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.justinimhoff.library.managers</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ViewManager <span style="color: #000000; font-weight: bold;">extends</span> Singleton
    <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.justinimhoff.library.managers</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.events.Event</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.events.EventDispatcher</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.events.IEventDispatcher</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.utils.Dictionary</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.utils.getDefinitionByName</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.utils.getQualifiedClassName</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     *
     * General Singleton management class. Extend this class to create
     * a singleton manager.
     *
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Singleton <span style="color: #000000; font-weight: bold;">implements</span> IEventDispatcher
    <span style="color: #009900;">&#123;</span>
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * internal dictionary to keep class instances
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> var instanceDict<span style="color: #339933;">:</span><span style="color: #003399;">Dictionary</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Dictionary</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * removes the item from the dictionary for garbage collection
         * @param managementClass
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> function removeInstance<span style="color: #009900;">&#40;</span>managementClass<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">Class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            var instance<span style="color: #339933;">:</span>Singleton <span style="color: #339933;">=</span> instanceDict<span style="color: #009900;">&#91;</span>managementClass<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>instance <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                delete instanceDict<span style="color: #009900;">&#91;</span>managementClass<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Get the single instance
         * @return the single instance
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> function getInstance<span style="color: #009900;">&#40;</span>managementClass<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">Class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:*</span>
        <span style="color: #009900;">&#123;</span>
            var instance<span style="color: #339933;">:</span>Singleton <span style="color: #339933;">=</span> instanceDict<span style="color: #009900;">&#91;</span>managementClass<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>instance <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//create a new instance of class managementClass  </span>
                instance <span style="color: #339933;">=</span> Singleton<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> managementClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>instance <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">throw</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;getInstance can only be called for Classes extending Singleton&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">return</span> instance<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Dispatcher to user in singletons
         */</span>
        <span style="color: #000000; font-weight: bold;">protected</span> var dispatcher<span style="color: #339933;">:</span>EventDispatcher <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> EventDispatcher<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         *
         * We only want one of these - Singletons are actually more performant than static management classes
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function Singleton<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            onConstructor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Used to interface with internal dispatcher
         * @param type
         * @param listener
         * @param useCapture
         * @param priority
         * @param useWeakReference
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function addEventListener<span style="color: #009900;">&#40;</span>type<span style="color: #339933;">:</span><span style="color: #003399;">String</span>, listener<span style="color: #339933;">:</span>Function, useCapture<span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>, priority<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>, useWeakReference<span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            dispatcher.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span>type, listener, useCapture, priority, useWeakReference<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Used to interface with internal dispatcher
         * @param type
         * @param listener
         * @param useCapture
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function removeEventListener<span style="color: #009900;">&#40;</span>type<span style="color: #339933;">:</span><span style="color: #003399;">String</span>, listener<span style="color: #339933;">:</span>Function, useCapture<span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            dispatcher.<span style="color: #006633;">removeEventListener</span><span style="color: #009900;">&#40;</span>type, listener, useCapture<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Used to interface with internal dispatcher
         * @param event
         * @return
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function dispatchEvent<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">:</span><span style="color: #003399;">Event</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> dispatcher.<span style="color: #006633;">dispatchEvent</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Used to interface with internal dispatcher
         * @param type
         * @return
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function hasEventListener<span style="color: #009900;">&#40;</span>type<span style="color: #339933;">:</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> dispatcher.<span style="color: #006633;">hasEventListener</span><span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Used to interface with internal dispatcher
         * @param type
         * @return
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function willTrigger<span style="color: #009900;">&#40;</span>type<span style="color: #339933;">:</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> dispatcher.<span style="color: #006633;">willTrigger</span><span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         *
         * Conceptually private constructor.
         * Manages the singleton document dictionary.
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">protected</span> function onConstructor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            var className<span style="color: #339933;">:</span><span style="color: #003399;">String</span> <span style="color: #339933;">=</span> getQualifiedClassName<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            var managementClass<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">Class</span> <span style="color: #339933;">=</span> getDefinitionByName<span style="color: #009900;">&#40;</span>className<span style="color: #009900;">&#41;</span> as <span style="color: #000000; font-weight: bold;">Class</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>managementClass <span style="color: #339933;">==</span> Singleton<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">throw</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Singleton is a base class that cannot be instantiated&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            var instance<span style="color: #339933;">:</span>Singleton <span style="color: #339933;">=</span> instanceDict<span style="color: #009900;">&#91;</span>managementClass<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>instance <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">throw</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Classes extending Singleton can only be instantiated once by the getInstance method&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                instanceDict<span style="color: #009900;">&#91;</span>managementClass<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/favorite-singleton-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ant + Library SWC + Namespaces</title>
		<link>http://justinimhoff.com/ant-library-swc-namespaces/</link>
		<comments>http://justinimhoff.com/ant-library-swc-namespaces/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 23:15:31 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=198</guid>
		<description><![CDATA[There are many cases where you will build a custom component library and use namespaces, this is what I have found to work the best. Can post step for creating and using a manifest, but there are many links on google. The key to this is using the current Adobe namespaces as not to overwrite and [...]]]></description>
			<content:encoded><![CDATA[<p>There are many cases where you will build a custom component library and use namespaces, this is what I have found to work the best. Can post step for creating and using a manifest, but there are many links on google. The key to this is using the current Adobe namespaces as not to overwrite and adding your own. When deploying the swc, make sure it is copied back into the libs directory so Flash builder can pick up the changes.<br />
<br/><br/></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
    <span style="color: #339933;">&lt;!--</span> build component library swc <span style="color: #339933;">--&gt;</span>
    <span style="color: #339933;">&lt;</span>macrodef name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;flex-compile-production-swc&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>attribute name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;swc-name&quot;</span> <span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;</span>attribute name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;locale&quot;</span>
            <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;en_US&quot;</span> <span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;</span>sequential<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>compc output<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${source.libs}/library/@{swc-name}${version}.swc&quot;</span>
                locale<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;@{locale}&quot;</span>
                maxmemory<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;768m&quot;</span>
                fork<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span>
                debug<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;false&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
                <span style="color: #339933;">&lt;</span>source<span style="color: #339933;">-</span>path path<span style="color: #339933;">-</span>element<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${source.flex.dir}&quot;</span> <span style="color: #339933;">/&gt;</span>
                <span style="color: #339933;">&lt;</span>include<span style="color: #339933;">-</span>sources dir<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${source.flex.dir}/com/justinimhoff/library/&quot;</span>
                    includes<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;**/*.as **/*.mxml&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
                <span style="color: #339933;">&lt;</span>namespace uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://ns.adobe.com/mxml/2009&quot;</span>
                    manifest<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${FLEX_HOME}/frameworks/mxml-2009-manifest.xml&quot;</span> <span style="color: #339933;">/&gt;</span>
                <span style="color: #339933;">&lt;</span>namespace uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;library://ns.adobe.com/flex/spark&quot;</span>
                    manifest<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${FLEX_HOME}/frameworks/spark-manifest.xml&quot;</span> <span style="color: #339933;">/&gt;</span>
                <span style="color: #339933;">&lt;</span>namespace uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;library://ns.adobe.com/flex/mx&quot;</span>
                    manifest<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${FLEX_HOME}/frameworks/mx-manifest.xml&quot;</span> <span style="color: #339933;">/&gt;</span>
                <span style="color: #339933;">&lt;</span>namespace uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.adobe.com/2006/mxml&quot;</span>
                    manifest<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${FLEX_HOME}/frameworks/mxml-manifest.xml&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
                <span style="color: #339933;">&lt;</span>namespace uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;library://justinimhoff.com/flex/components&quot;</span>
                    manifest<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${source.libs.components}/component-manifest.xml&quot;</span> <span style="color: #339933;">/&gt;</span>
                <span style="color: #339933;">&lt;</span>include<span style="color: #339933;">-</span>namespaces<span style="color: #339933;">&gt;</span>library<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//justinimhoff.com/flex/components&lt;/include-namespaces&gt;</span>
&nbsp;
                <span style="color: #339933;">&lt;!--</span> Externally linked Flex libraries <span style="color: #339933;">--&gt;</span>
                <span style="color: #339933;">&lt;</span>compiler.<span style="color: #006633;">external</span><span style="color: #339933;">-</span>library<span style="color: #339933;">-</span>path dir<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${FLEX_HOME}/frameworks/&quot;</span>
                    append<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libs/player/playerglobal.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libs/framework.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libs/spark.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libs/sparkskins.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libs/utilities.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libs/textLayout.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libs/rpc.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libs/flex.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;locale/${locale}/framework_rb.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;locale/${locale}/rpc_rb.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                <span style="color: #339933;">&lt;/</span>compiler.<span style="color: #006633;">external</span><span style="color: #339933;">-</span>library<span style="color: #339933;">-</span>path<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;/</span>compc<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>copy preservelastmodified<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span>
                todir<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${output.dir.rsls}&quot;</span><span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>fileset casesensitive<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;yes&quot;</span>
                    dir<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${source.libs}/library/&quot;</span><span style="color: #339933;">&gt;</span>
                    <span style="color: #339933;">&lt;</span>include name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;@{swc-name}${version}.swc&quot;</span> <span style="color: #339933;">/&gt;</span>
                <span style="color: #339933;">&lt;/</span>fileset<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;/</span>copy<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>echo<span style="color: #339933;">&gt;</span>Succesfully compiled @<span style="color: #009900;">&#123;</span>swc<span style="color: #339933;">-</span>name<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>echo<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>sequential<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>macrodef<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/ant-library-swc-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kinect + Street View + Adobe AIR</title>
		<link>http://justinimhoff.com/kinect-street-view-adobe-air/</link>
		<comments>http://justinimhoff.com/kinect-street-view-adobe-air/#comments</comments>
		<pubDate>Sat, 28 May 2011 16:14:38 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[User Interface Design]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=174</guid>
		<description><![CDATA[Quick demonstration of Kinect controlling Google Street View with Adobe AIR: Controls: Rotate body right: rotate image right Rotate Body left: rotate image left Walk (knee up): progress forward Lean Up: look up Lean Down: look down This is a quick demonstration of leveraging the kinect for NUI with Street View. The example above uses [...]]]></description>
			<content:encoded><![CDATA[<p>Quick demonstration of Kinect controlling Google Street View with Adobe AIR:</p>
<p><iframe width="640" height="390" src="http://www.youtube.com/embed/IajxPB-qSzs" frameborder="0" allowfullscreen></iframe><br />
<br/><br />
Controls:</p>
<ul>
<li>Rotate body right: rotate image right</li>
<li>Rotate Body left: rotate image left</li>
<li>Walk (knee up): progress forward</li>
<li>Lean Up: look up</li>
<li>Lean Down: look down</li>
</ul>
<p>This is a quick demonstration of leveraging the kinect for NUI with Street View. The example above uses <a href="http://code.google.com/p/as3openni/">AS3OpenNI</a> (shout out) with Google Street View in Adobe AIR.</p>
]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/kinect-street-view-adobe-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe Flex versioning with ant and cache control</title>
		<link>http://justinimhoff.com/adobe-flex-versioning-with-ant-and-cache-control/</link>
		<comments>http://justinimhoff.com/adobe-flex-versioning-with-ant-and-cache-control/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 02:06:29 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=148</guid>
		<description><![CDATA[So  you are building a enterprise Flex application that uses automated builds with ant. You are running into the issue of multiple modules and assets that use the same name but you want to identify the swf by the specific version of the build and maybe even deploy multiple builds in the same structure allowing [...]]]></description>
			<content:encoded><![CDATA[<p>So  you are building a enterprise Flex application that uses automated builds with ant. You are running into the issue of multiple modules and assets that use the same name but you want to identify the swf by the specific version of the build and maybe even deploy multiple builds in the same structure allowing them to share un- changed resources. Or just maybe you want to make sure that when you deploy a new production build, that the swfs are not cached. The below code will help with both scenarios. As a quick background, when using RSLs, the RSL contains a digest or UID that when the application is compiled, it is compiled against that digest. When requesting RSLs, the application request RSLs by name but then also validates the digest against what the application was compiled against to ensure it is using the latest / correct library.</p>
<p/>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">       <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * property in the build file that identifies the version number used to build swfs
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">const</span> BUILD_PROPERTY_VERSION_IDENTIFIER<span style="color: #339933;">:</span><span style="color: #003399;">String</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'version'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * The regular expression that only allows numbers, dashes, and period from the build
         * property string
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">const</span> BUILD_PROPERTY_VERSION_REG_EXP<span style="color: #339933;">:</span>RegExp <span style="color: #339933;">=</span> <span style="color: #339933;">/</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">^</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">-</span>.<span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span>g<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#91;</span>Embed<span style="color: #009900;">&#40;</span>source<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;../build/build.properties&quot;</span>, mimeType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;application/octet-stream&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * Embedded build property file
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">const</span> embeddedBuildFile<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">Class</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * With searching if an item is not found it return -1, so anything 0 or greater means the
         * item has been found at least once in the string.
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">const</span> ITEM_FOUND<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * The version of the application
         * @private
         */</span>
        <span style="color: #000000; font-weight: bold;">private</span> var _appVersion<span style="color: #339933;">:</span><span style="color: #003399;">String</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * If the property is not already set, loop through all build properties that have been embedded
         * when compiled until the property contains an identifier related to the build version. Once found,
         * clean up any characters that are not of a build number and set property
         * @return build version number
         *
         */</span>
        <span style="color: #000000; font-weight: bold;">public</span> function get version<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">String</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_appVersion <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
	        <span style="color: #666666; font-style: italic;">// Create a new class of the embedd type and cast as a string to initialize</span>
		var buildProperties<span style="color: #339933;">:</span><span style="color: #003399;">String</span> <span style="color: #339933;">=</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> embeddedBuildFile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Split all line breaks into an array</span>
                var arr<span style="color: #339933;">:</span><span style="color: #003399;">Array</span> <span style="color: #339933;">=</span> buildProperties.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                var i<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                var len<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> arr.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
                var buildProperty<span style="color: #339933;">:</span><span style="color: #003399;">String</span><span style="color: #339933;">;</span>
	       <span style="color: #666666; font-style: italic;">// Loop through all poperties untile the identifier is found and set</span>
                <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    buildProperty <span style="color: #339933;">=</span> arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>buildProperty.<span style="color: #006633;">search</span><span style="color: #009900;">&#40;</span>BUILD_PROPERTY_VERSION_IDENTIFIER<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> ITEM_FOUND<span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        _appVersion <span style="color: #339933;">=</span> buildProperty.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span>BUILD_PROPERTY_VERSION_REG_EXP, <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">return</span> _appVersion<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span></pre></div></div>

<p>We want to essentially copy this same structure while also promote caching when possible. In most build scenarios you are versioning the application and maybe using automated incremental build numbers. This is a great thing and something we want to take advance of, so the first step is to embedded the build.properties file (properties.xml would require parsing as XML) so we have the incremented version or build number that the swf is being built as. When embedding the properties file, you can try decompiling the swf, but you will not be able to read out the file &#8211; only during runtime initialization will the values be available. This may be a great thing if you are using encryption keys in the application. So the file has the latest build so then the next step just comes to instantiating and looping through the values until the expected property is found and then just clean up the property values based on your versioning scheme.</p>
<p>The next step to this is to build out your applications, modules, and runtime assets with the build version appended. Example; Application.1.2.3-45678.swf or module.1.2.3-45678.swf. This allows a visual identifier of the build version and ability to deploy multiple applications of different builds to the same directory. Now the real reason we have embedded the version in the application is we need to know the URL for the assets or the modules &#8211; we know the identifier but need to append the version. This will allow an application to only load the correct module or asset swf for the specific build. This example can also be extended to custom libraries  or even as RSLs.</p>
<p>The other benefit to this approach is caching, when building Flex application we have all run into informing the client to clear there cache and try again &#8211; but no more. In this scenario the application.html page will be requesting a completely different swf file because it will be referencing the swf with the appended build, so it will always be fresh &#8211; but not just that, we also will be leveraging the caching of the swf in the browser. If the application.html file is pointing to the same swf consecutively it will use the cache of the swf and you will no worry about the client having the latest and greatest. You can use this in a singleton or static through-ought the application if there are other properties that might be worth noting like server build time . Can definitely go into more detail but hopefully this can help other out and is a good start.</p>
]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/adobe-flex-versioning-with-ant-and-cache-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flatten nested Objects in Flex</title>
		<link>http://justinimhoff.com/flatten-nested-objects-in-flex/</link>
		<comments>http://justinimhoff.com/flatten-nested-objects-in-flex/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 15:12:03 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Adobe]]></category>

		<guid isPermaLink="false">http://justinimhoff.com/?p=137</guid>
		<description><![CDATA[This might seem like a small thing, but when you are requesting results back from the Google Maps API for example, and are presented with dynamic nested objects, your validation can be daunting. This simple function will allow you to pass in the object to be flattened into a blank object or an object you [...]]]></description>
			<content:encoded><![CDATA[<p>This might seem like a small thing, but when you are requesting results back from the Google Maps API for example, and are presented with dynamic nested objects, your validation can be daunting. This simple function will allow you to pass in the object to be flattened into a blank object or an object you would like to append to. This will allow simple validation of the object, and the ability to convert to a strict type object if necessary. This was used in a singleton utility management class, if to be used in a static, add static and recursively call the class.</p>
<p>Simple = Yes / Time Saver = Hells Yes!</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">        <span style="color: #000000; font-weight: bold;">public</span> function pushToFlatObject<span style="color: #009900;">&#40;</span>source<span style="color: #339933;">:</span><span style="color: #003399;">Object</span>, pushTo<span style="color: #339933;">:</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">for</span> each <span style="color: #009900;">&#40;</span>var item<span style="color: #339933;">:*</span> in source<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ObjectUtil.<span style="color: #006633;">isSimple</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    var objectInfo<span style="color: #339933;">:</span><span style="color: #003399;">Object</span> <span style="color: #339933;">=</span> ObjectUtil.<span style="color: #006633;">getClassInfo</span><span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    var i<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                    var len<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">int</span> <span style="color: #339933;">=</span> objectInfo.<span style="color: #006633;">properties</span>.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
                    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        <span style="color: #666666; font-style: italic;">//Show the name and the value</span>
                        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#91;</span>objectInfo.<span style="color: #006633;">properties</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">localName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> item<span style="color: #009900;">&#41;</span>
                        <span style="color: #009900;">&#123;</span>
                            pushTo<span style="color: #009900;">&#91;</span>objectInfo.<span style="color: #006633;">properties</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">localName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> item<span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    pushToFlatObject<span style="color: #009900;">&#40;</span>item, pushTo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://justinimhoff.com/flatten-nested-objects-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

