<?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>Curious Minds Media Labs - &#187; air</title>
	<atom:link href="http://www.curiousm.com/labs/category/air/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.curiousm.com/labs</link>
	<description>iOS, Mobile, Design and Technology Tutorials</description>
	<lastBuildDate>Mon, 11 Feb 2013 19:37:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>NetConnection: Flash Remoting in smaller AS3 projects</title>
		<link>http://www.curiousm.com/labs/2011/07/08/netconnection-flash-remoting-in-smaller-as3-projects/</link>
		<comments>http://www.curiousm.com/labs/2011/07/08/netconnection-flash-remoting-in-smaller-as3-projects/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 17:03:16 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[desktop application]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AIR Application]]></category>
		<category><![CDATA[Desktop Application]]></category>
		<category><![CDATA[Flash Remoting]]></category>
		<category><![CDATA[Remote Services]]></category>
		<category><![CDATA[var]]></category>
		<guid isPermaLink="false">http://www.curiousm.com/labs/?p=1339</guid>
		<description><![CDATA[What is NetConnection? Located in the flash.net package, NetConnection inherits from EventDispatcher and then Object. It is a simple way to open a connection to a remote server, call services from it and then implement the return values into your ActionScript 3.0 project. This works even in standalone Adobe Air applications. Although it is not [...]]]></description>
			<content:encoded><![CDATA[<p>What is <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetConnection.html" target="_blank">NetConnection</a>? Located in the flash.net package, NetConnection inherits from EventDispatcher and then Object. It is a simple way to open a connection to a remote server, call services from it and then implement the return values into your ActionScript 3.0 project. This works even in standalone Adobe Air applications. Although it is not the best option for larger projects, it is a simple way to call remote services from a server without having to set up Value Objects, let alone a complex system. <span id="more-1339"></span> Quoting directly from the Adobe site:</p>
<blockquote><p><em>&#8220;The NetConnection class creates a bidirectional connection between a Flash Player or AIR application and a Flash Media Server application or between a Flash Player or AIR application and an application server running Flash Remoting. A NetConnection object is like a pipe between the client and the server. Use NetStream objects to send streams through the pipe.<br />
Without Flash Media Server, you can use the NetConnection class to play video and MP3 files from a local file system or from a web server.&#8221;</em></p></blockquote>
<p>As you can see, NetConnection already opens up an array of possibilities. In this specific case scenario, let me first start off by saying that I was implementing the <a href="http://www.actionscript.org/resources/articles/679/1/MVC-Design-Pattern/Page1.html" target="_blank">MVC design pattern</a> (Model View Controller). I was building a small Adobe Air Application using the Flex 4 SDK, and heavily relying on ActionScript 3.0 for most of the coding. My objective was to call remote services on three different remote servers, which would return values stating that &#8220;Yes, this server is online.&#8221; Then using the variables that it returned, set up a custom event that would fire off stating whether or not the specific server was online. My Controller would listen for the event, and upon receiving it call the respective function that would change my view to say &#8220;Let&#8217;s turn on the green button instead of the red button, because this server is online!&#8221; Here is the code to set up a connection for a specific server:</p>
<div id="attachment_1356" class="wp-caption alignnone" style="width: 864px"><a href="http://www.curiousm.com/labs/files/2011/07/example.png"><img src="http://www.curiousm.com/labs/files/2011/07/example.png" alt="NetConnection Example" width="854" height="723" class="size-full wp-image-1356" /></a><p class="wp-caption-text">NetConnection Example</p></div>
<p><strong>Step 1: Import related classes</strong><br />
You&#8217;re going to want to import flash.net packages; NetConnection, ObjectEncoding, and Responder.</p>
<p><strong>Step 2: Implement variables and Constructor</strong><br />
Implement whatever public class variables you want, and then pass in an null IEventDispatcher object in the constructor function and call the super of that class. This is only to prevent any issues with dispatching events from this ConnectionController class.</p>
<p><strong>Step 3: Create a function to check a server</strong><br />
Make sure the return type of this function is void. Inside this, create a private variable by declaring the var keyword, for an instance of NetConnection, and any other variables having to do with this one specific function. Declare the ObjectEncoding variable, and the connect variable in the new NetConnection variable you just declared.</p>
<p><strong>Step 4: Call a function and set up dispatchers</strong><br />
Use _gateway.call(locationOfFunctionOnRemoteServer, new Responder(functionIfReturnValue, functionIfError), &#8230;.arguments); to make a call to the server, you can implement this line for however many functions you want to call in this one operation. After this, set up the nested functions that are called in the _gateway.call method, and fire off dispatchers with the related custom event based on a return from the server.</p>
<p>And there you have it, a simple way to call and get a return value from a remote server in AS3.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2011/07/08/netconnection-flash-remoting-in-smaller-as3-projects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating ASDocs with ANT &amp; Flash Builder Part 3. Customizing the Documentation Template.</title>
		<link>http://www.curiousm.com/labs/2011/06/27/creating-asdocs-with-ant-flash-builder-part-3-customizing-the-documentation-template/</link>
		<comments>http://www.curiousm.com/labs/2011/06/27/creating-asdocs-with-ant-flash-builder-part-3-customizing-the-documentation-template/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 13:51:59 +0000</pubDate>
		<dc:creator>Momchilova Ralica</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[ANT]]></category>
		<category><![CDATA[ant build file]]></category>
		<category><![CDATA[ant tasks]]></category>
		<category><![CDATA[ant tools]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[asdoc]]></category>
		<category><![CDATA[build file]]></category>
		<category><![CDATA[buildfile.xml]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[generate documentation]]></category>
		<category><![CDATA[project documentation]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">http://www.curiousm.com/labs/?p=1145</guid>
		<description><![CDATA[3. Customizing the HTML template for your Flash Builder Project. There’s no point doing good work if others don’t know about it or can’t understand what you did. When it comes to developing lengthy applications a well written documentation is a must. A well written documentation which compliments your project&#8217;s design shows commitment to the project [...]]]></description>
			<content:encoded><![CDATA[<h3>3. Customizing the HTML template for your Flash Builder Project.</h3>
<p>There’s no point doing good work if others don’t know about it or can’t understand what you did. When it comes to developing lengthy applications a well written documentation is a must. A well written documentation which compliments your project&#8217;s design shows commitment to the project and a professional feel.</p>
<p>In <strong><a href="http://www.curiousm.com/labs/2011/04/18/creating-asdocs-with-ant-flash-builder-part-1/">Part 1</a></strong> of this tutorial we covered ANT installation. <strong><a href="http://www.curiousm.com/labs/2011/04/26/creating-asdocs-with-ant-flash-builder-part-2/">Part 2</a> </strong>explains the best practices for writing comments inside your project&#8217;s classes which later are read by ANT and included in the project documentation. <strong>Part 3</strong> is the final part of this series. It will help you understand how your documentation is structured, and what can be done to customize the HTML template used by ANT to generate the documentation.<br />
The default documentation template is the same as the one used by Adobe to document the ActionScript 3.0 language. Here is a link which I am sure you have visited before:</p>
<h5><strong><a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/class-summary.html#top">http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/class-summary.html#top</a></strong></h5>
<p><strong>Good to know:</strong></p>
<p><strong>What are HTML templates?</strong> An HTML template is a ready-made design of the HTML page. The HTML template usually include most of the source files necessary for further customizing the template. It can be edited using WYSIWYG editors such as Frontpage, Dreamweaver etc.</p>
<p><strong>CSS</strong> - <strong>Cascading Style Sheets </strong>is a language used to create stylesheets in which you can describe presentation semantics, its used mainly with HTML and XHTML pages. It can also be used with Adobe Flash Builder and other. It&#8217;s a good practice to separate the styling of your project in a CSS file. This way the designer and the developer for example can work together and have a smooth workflow.</p>
<p><strong>Where is the template used by ANT ?</strong></p>
<p>The path to the template should look like this:<br />
<span style="color: #ff6600"> /Applications/Adobe Flash Builder 4.5/sdks/4.5.0/asdoc/templates/</span>.</p>
<p><a href="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-5.41.49-AM.png"><img class="alignnone size-full wp-image-1258" src="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-5.41.49-AM.png" alt="" width="580" height="157" /></a></p>
<p>Inside the &#8220;templates&#8221; folder you will find all the components that make the HTML template. You cannot modify the template directly, but you can create a copy and assign it&#8217;s path in the ANT build script instead of using the default.</p>
<p><strong>The CSS:</strong></p>
<p><strong> </strong><a href="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-8.34.25-AM-e1309178339482.png"><img class="alignleft size-full wp-image-1266" src="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-8.34.25-AM-e1309178339482.png" alt="" width="326" height="174" /></a>Through this CSS file you can assign styles to all the components that make your documentation pages. You can easily make changes to the documentation pages by modifying the styles.css (path: /Applications/Adobe Flash Builder 4.5/sdks/4.5.0/asdoc/templates/style.css).</p>
<p>In order to modify an element&#8217;s style you need to begin your declaration with the element&#8217;s class name. From then it&#8217;s simple. Assign the new properties as shown on the image above.</p>
<p>You can see the class names of the elements you would like to modify by opening the .html files of the template. Here is an example that shows where and how the class is defined for the elements and also how the stylesheet is assigned to the HTML page. If you have found a CSS stylesheet that fits your needs you could even save time and assign it instead of the default one. Then just make sure to change the class names for the elements that require customization. The global settings would stay the same.</p>
<h3><a href="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-8.34.25-AM-e1309178339482.png"></a><a href="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-8.44.41-AM.png"><img src="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-8.44.41-AM.png" alt="" width="546" height="159" /></a></h3>
<p><strong>Manipulating the HTML itself:</strong></p>
<p>You could manipulate the HTML directly and change the layout of your page as well. I would recommend using Dreamweaver or other free editing software both for the CSS and the HTML. This would help you edit quickly and to see the results immediately as Dreamweaver for example has views that allow you to see the modifications live as you are making them.</p>
<p><a href="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-9.10.58-AM.png"><img class="aligncenter size-full wp-image-1282" src="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-9.10.58-AM.png" alt="" width="544" height="315" /></a></p>
<p><strong>Finishing up:</strong></p>
<p>The range of modifications you can make to your template has almost no limits. All you need is a basic understanding of the HTML and CSS language and a good editor software.</p>
<p>Once you are ready to use the template or test it you need to assign it inside your build.xml file. (explained in Part 2) Here&#8217;s the example syntax:</p>
<pre class="brush: plain; title: ; notranslate">&lt;arg line=&quot;-templates-path '/Applications/Adobe Flash Builder 4/sdks/4.1.0/asdoc/YourTemplateName'&quot;/&gt;</pre>
<p><a href="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-9.30.02-AM.png"><img class="aligncenter size-full wp-image-1288" src="http://www.curiousm.com/labs/files/2011/06/Screen-shot-2011-06-27-at-9.30.02-AM.png" alt="" width="565" height="56" /></a></p>
<p>Above is a snippet of one of CuriousMinds&#8217; project documentation build.xml files.  As you can see there are settings editable directly through the build.xml file like the window-title and other. One of my favorite things to do is to make sure the company branding is displayed as well as the client&#8217;s. An ideal place for the Author&#8217;s name and the Company branding is the footer (line 66).</p>
<p>This is all there is to customizing you template. If you have any questions post and I will try to be quick to answer.</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2011/06/27/creating-asdocs-with-ant-flash-builder-part-3-customizing-the-documentation-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex and Spring: Communication over BlazeDS &#8211; Part I</title>
		<link>http://www.curiousm.com/labs/2011/06/13/flex-and-spring-communication-over-blazeds-part-i/</link>
		<comments>http://www.curiousm.com/labs/2011/06/13/flex-and-spring-communication-over-blazeds-part-i/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 15:04:28 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Spring]]></category>
		<guid isPermaLink="false">http://www.curiousm.com/labs/?p=1181</guid>
		<description><![CDATA[Leveraging a Spring backend in your Flex application can be a great way to gain access to powerful java tools and server technologies, but getting your client and server all wired up can be pretty challenging, especially for the newcomer. I recently had the opportunity to explore this Pandora&#8217;s box, and came up with a [...]]]></description>
			<content:encoded><![CDATA[<p>Leveraging a Spring backend in your Flex application can be a great way to gain access to powerful java tools and server technologies, but getting your client and server all wired up can be pretty challenging, especially for the newcomer. I recently had the opportunity to explore this Pandora&#8217;s box, and came up with a Flex-Java solution that may work for you, depending on your project&#8217;s needs. In this series of tutorials I want to share with you the way in which I went about getting my application up and running in hopes that other newbies out there might have some success integrating these technologies.</p>
<p><span id="more-1181"></span></p>
<p>NOTE: Please download attached source files from <a href="http://clients.curiousm.com/flex_and_spring/example.zip">here</a> to help you with this tutorial.</p>
<p>I wanted to make use of the Spring framework in my Java backend because of its flexibility and streamlined development. I wanted Hibernate integration also for data persistence to a MySQL database, which I knew Spring could provide me. It seemed to me that this stack would be the perfect combination of tools to get my application off the ground, but I wasn&#8217;t quite sure how to go about putting all these pieces together.</p>
<p>A little research on this topic revealed some solutions like Spring Roo with the Flex scaffolding extensions which, at least at first, seemed would glue all these components together with ease. I&#8217;m sure the Spring Roo project, once it matures a little and stabilizes, will be a viable way to generate the Java classes and Flex remoting scaffold necessary to build an application. That being said, the amount of difficulty I had in getting Spring Roo and Flex to work together was immense. I also have a huge aversion to using new tools to generate code for me that are not yet widely embraced or supported by the community at large, and which I don&#8217;t fully understand inside and out. When eventually the excrement hits the air circulation device, I want to know exactly where a system is failing and why, even if it means spending a few extra hours writing boilerplate code from scratch. I do, however, appreciate the work that Jeremy Grelle et al. have done on this project, but at present, the Roo-Flex project isn&#8217;t stable enough for my tastes. Upon realizing this, I decided to roll up my sleeves and tie the pieces together myself.</p>
<p><strong>Setting up BlazeDS and Tomcat</strong></p>
<p>BlazeDS is a great way to get Flex and java talking to one another. It is free, which lowers the cost barrier for you and your client, and is relatively easy to install. A popular method of getting up and running quickly is to install the BlazeDS turnkey server. This is ostensibly a Tomcat server, bundled with a bunch of very typical examples of how BlazeDS can be utilized. You can download this package from the <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS">Adobe Labs Website</a>, or if you already have a Tomcat installation you want to develop against, you may grab the WAR file and deploy it yourself. Instructions for deploying BlazeDS, starting the server and running the examples can all be found on the website, and in the enclosed documentation.</p>
<p><strong>Maven Management</strong></p>
<p>Once you have a Tomcat installation and BlazeDS running in the container, we can start thinking about how to structure our java project and how to incorporate the Spring and Hibernate libraries into our project. I found SpringSource Tool Suite (STS) to be a useful IDE to develop the java side of my application. It is another Eclipse spinoff, so those familiar with this IDE will feel right at home in these environs. If you use Maven to manage your project dependencies, you can get almost everything you need by adding the requisite nodes to your pom.xml file, or by using the M2Eclipse pom editor to search for and manage your project jars. You can find instructions on installing M2Eclipse for STS on the <a href="http://m2eclipse.sonatype.org/"></a>M2Eclipse project website, and you can get SpringSource Tool Suite from <a href="http://www.springsource.com/developer/sts">here</a>.</p>
<p>Once we have these pieces in place, let&#8217;s start by making a new project in STS. Choose &#8216;New Java Project&#8217; from &#8216;File&#8217; in the main menu of the application, and give it a name. This is the most basic java project configuration, to which we are going to add Maven support, as well as some project facets to get the resources and structure of our project tightened up. The next thing we want to do is enable dependency management with Maven. We&#8217;ll do that by right clicking on the project in our package explorer, and choosing &#8216;Maven -&gt; Enable Dependency Management&#8217;. Here we are presented with some options. Because we are just creating a simple tutorial application here, I&#8217;m leaving my Group Id and Artifact Id alone, and providing a simple name and description for the heck of it. When finished with this step, a pom.xml file will be created in the project folder which we can edit to add dependencies automatically to the build path.</p>
<p><strong>Project Facets</strong></p>
<p>The way Eclipse organizes a project and structures a project to make it runnable in different environments is to add &#8216;facets&#8217; to the project. We are going to add facets to this project now to transform this &#8216;vanilla&#8217; java project into web application deployable to our Tomcat server. Again, right click on the project folder in the Package Explorer and choose &#8216;Properties&#8217;. You&#8217;ll see a menu item in the list called &#8216;Project Facets&#8217;. Choose that, and click the link to &#8216;Convert to faceted form…&#8217;. From the list that appears in the Project Facets Pane, select the &#8216;Dynamic Web Module&#8217; checkbox, leave the &#8216;Java&#8217; checkbox selected and click &#8216;OK&#8217;.</p>
<p>If you were paying attention you&#8217;ll notice that Eclipse just created a folder called &#8216;WebContent&#8217;, and  &#8216;META-INF&#8217; and &#8216;WEB-INF&#8217; folders inside that folder. This is the basic structure our java web application will take on when we export and deploy it.</p>
<p><strong>Spring Dependencies</strong></p>
<p>The Maven dependencies found in the attached project&#8217;s pom.xml file will give you the libraries we&#8217;re going to make use of in the next step of our tutorial. Note that there may be updates to some of these release jars by now, but avoiding the confusion of dependency compatibility is one of my goals in writing this post. Try using this list of dependencies before looking for newer releases, and save yourself some aggravation.</p>
<p>Feel free to copy this list directly into your project&#8217;s pom. Once we have done this, we are ready to begin building our java application&#8217;s context. You should also see that in the package explorer, our folder containing Maven Dependencies has 17 new jar files in it. These are, of course, the dependencies we&#8217;ve just added to our pom.xml.</p>
<p><strong>Spring Flex Integration Jars</strong></p>
<p>In addition to the above resources, we&#8217;re going to need the Flex Spring integration jars. You can get them from the following <a href="http://www.springsource.org/spring-flex">address</a>.</p>
<p>Once you&#8217;ve downloaded these jars, you&#8217;ll want to make sure they get deployed along with your maven managed jars. I made a folder inside my project called &#8216;jar&#8217; into which I&#8217;ve placed additional dependencies. I&#8217;ve included my jars folder here in the project archive, so you can unzip that folder into your project directory and use them. There are a few other jars in this folder. Do yourself a favor and use my jars because there are some dependencies that we have not discussed, which I spent too many hours starting and restarting my server, getting ClassDefinitionNotFound errors, and searching the web for the correct jars containing the right Classes to get this project running. Please trust me on this one. To get the items in the &#8216;jars&#8217; folder to deploy properly, you want to make sure there is a corresponding entry in your &#8216;Web Deployment Assembly&#8217; properties for this project. Go into the Properties for this project and select Deployment Assembly. This is where we can define mappings for deployment of our resources. If it isn&#8217;t done already, map your jar folder to &#8216;/WEB-INF/lib&#8217;. Our jars will now be in place when we deploy our web application.</p>
<p><strong>Part I Wrap Up</strong></p>
<p>Because this process of building all the components that make up this application is quite involved, I am breaking this into smaller, less daunting steps. We now have an STS project with all of the foundation to start coding our backend, and after that, to call our services from a Flex client. Be sure to check back soon for the second part of this tutorial, when we get into some of the more fun aspects of building this project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2011/06/13/flex-and-spring-communication-over-blazeds-part-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating ASDocs with ANT &amp; Flash Builder Part 2. Writing AsDoc Comments.</title>
		<link>http://www.curiousm.com/labs/2011/04/26/creating-asdocs-with-ant-flash-builder-part-2/</link>
		<comments>http://www.curiousm.com/labs/2011/04/26/creating-asdocs-with-ant-flash-builder-part-2/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 13:39:07 +0000</pubDate>
		<dc:creator>Momchilova Ralica</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[ANT]]></category>
		<category><![CDATA[ant build file]]></category>
		<category><![CDATA[ant tasks]]></category>
		<category><![CDATA[ant tools]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[asdoc]]></category>
		<category><![CDATA[build file]]></category>
		<category><![CDATA[buildfile.xml]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[generate documentation]]></category>
		<category><![CDATA[project documentation]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">http://www.curiousm.com/labs/?p=897</guid>
		<description><![CDATA[2. Project Documentation Process for Ant on standalone Flash Fuilder 4.5. Common Glossary and Output. This tutorial covers the documentation process for Ant on Adobe® Flash Builder 4.5. You will be presented with the most common ASDoc comments, their purpose and output in the generated documentation, and examples of documentation page templates and their customization [...]]]></description>
			<content:encoded><![CDATA[<h3><span style="font-size: 20px"><strong>2. Project Documentation Process for Ant on standalone Flash Fuilder 4.5. Common Glossary and Output.</strong></span></h3>
<p>This tutorial covers the documentation process for Ant on Adobe® Flash Builder 4.5. You will be presented with the most common ASDoc comments, their purpose and output in the generated documentation, and examples of documentation page templates and their customization process.</p>
<p>This is <em>Part 2</em> of the Ant and Flash Builder 4.5 tutorial. If you have not yet installed and setup Ant on the standalone version of Flash Builder you can refer to <strong><a href="http://www.curiousm.com/labs/2011/04/18/creating-asdocs-with-ant-flash-builder-part-1/" target="_blank">Part 1</a></strong>. There you can get a step-by-step instruction on how to install and setup Ant.</p>
<p>Once you have installed and properly setup Ant on Flash Builder, it&#8217;s time to write some ASDoc comments in ActionScript® . When you generate the documentation later this code will be recognized by the Ant documentation tool and included in the generated project documentation. If you are thorough in your comments and update them along with the project&#8217;s development process, you will end up with one well written and detailed documentation and you will never forget what each class is used for.</p>
<h2>Good to know:</h2>
<h2><span style="font-size: 13px;font-weight: normal">•  Adobe&#8217;s help documentation is very detailed and shows all the best practices regarding the documentation process. It contains AsDoc comment examples and their formatting for all types of ActionScript classes.You can visit their documentation <span style="font-size: 15px;font-weight: bold"><a href="http://help.adobe.com/en_US/flex/using/WSd0ded3821e0d52fe1e63e3d11c2f44bb7b-7fed.html">here</a></span>.</span></h2>
<p>This post is an addition which will help you instantly see what the result of the most common AsDoc comments looks like in the generated documentation. I will also cover a few mistakes that are common and if not minded can slow down your workflow or be the cause for errors which can go unnoticed by the documentation tool.</p>
<p>•  There is a list of HTML tags you can use to format you AsDoc comments. Bear in mind that this list of tags is limited, and that while in some sections of an AsDoc comment you can use them, in other places they are not accepted and can produce an error.<br />
A summary of these HTML elements can be found <a href="http://help.adobe.com/en_US/flex/using/WSd0ded3821e0d52fe1e63e3d11c2f44bc36-8000.html"><strong><span style="font-size: medium">here</span></strong></a></p>
<p>•  There are two types of AsDoc comments: ActionScript comments and MXML comments.</p>
<h2>Examples:</h2>
<p><strong>ActionScript</strong> comments are declared to start with  /**  character sequence and the end is declared by */. Read the example below:</p>
<pre class="brush: as3; title: ; notranslate"> /**
*  The first sentence would be used to describe
*  the class. Next sentences only show in the
*  class' detail view.
*/
</pre>
<p><em><span style="font-size: small">An example of an AsDoc comment used to describe a class.</span></em><br />
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size: 13px;line-height: 19px"><em>output:</em></span></p>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size: 13px;line-height: 19px"><em><a href="http://www.curiousm.com/labs/files/2011/04/ClassDescr.png"><img class="alignnone size-full wp-image-1002" src="http://www.curiousm.com/labs/files/2011/04/ClassDescr.png" alt="" width="570" height="173" /></a></em></span><br />
<em><span style="font-size: small">Above is a list of classes and their short descriptions generated by the documentation tool. The short description on the right is the first sentence in your AsDoc comment for that class.</span></em></p>
<p>Below is a view of the same class&#8217; Detail Page.</p>
<p><a href="http://www.curiousm.com/labs/files/2011/04/classDetailView.png"><img class="size-full wp-image-1007 alignnone" src="http://www.curiousm.com/labs/files/2011/04/classDetailView.png" alt="" width="570" height="138" /></a></p>
<p>• Commenting Functions:</p>
<pre class="brush: as3; title: ; notranslate">/**
* AsDoc comment for the &lt;code&gt;onViewClick&lt;/code&gt;
* method.  HTML tags &lt;strong&gt;can&lt;/strong&gt; be used
* here.
* @param evt Parameter tags are
* descriptions of the parameters this
* method can take in.
*/
override protected function onViewClick(evt:MouseEvent):void{
switch(evt.currentTarget){</pre>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size: 13px;line-height: 19px"><em>output:</em></span><br />
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size: 13px;line-height: 19px"><em><a href="http://www.curiousm.com/labs/files/2011/04/ClassComment1.png"><img class="alignnone size-full wp-image-1077" src="http://www.curiousm.com/labs/files/2011/04/ClassComment1.png" alt="" width="570" height="178" /></a></em></span><br />
<em><span style="font-size: small">Above is a snapshot of a Class Detail View page generated by the documentation tool.</span></em></p>
<p><strong>MXML</strong> AsDoc comments:</p>
<pre class="brush: plain; title: ; notranslate">Comments start with the &lt;!--- characters and
end with  --&gt; character.</pre>
<p>This comment is placed after the xml ecoding declaration and does not require a CDATA block. You can use the same comment structure when you are commenting MXML components such as buttons, DataGrids, etc.</p>
<p>Here is an example of invalid implementation of the &lt;h1&gt;<strong>Header 1</strong>&lt;/h1&gt; tag used where it does not belong. The text encapsulated in the wrong tag is simply omitted in the output. If these errors are not corrected you would end up with unreadable documentation.<br />
<img src="http://www.curiousm.com/labs/files/2011/04/AsDocComment1.png" alt="" width="572" height="75" /></p>
<p><em><span style="font-size: small">This is an MXML AsDoc comment.</span></em><br />
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size: 13px;line-height: 19px"><em>output:</em></span><br />
<a href="http://www.curiousm.com/labs/files/2011/04/AsDocCommentOutput1.png"><img src="http://www.curiousm.com/labs/files/2011/04/AsDocCommentOutput1.png" alt="" width="570" height="68" /></a><br />
<em><span style="font-size: small">Above is a snapshot of a Class Detail View page generated by the documentation tool.</span></em></p>
<h2>Errors</h2>
<p>My advice is when you start a new project always setup your documentation along with the project. There is nothing worse than an already built project that you have to create documentation for. When you are put in a situation where you have to document an already created project prepare to be patient and expect errors.<br />
Here are a few common things that would cause a Build fail:</p>
<p>• Improperly imported classes or classes that have not been imported at all. Even though Flash Builder will run your project, and build successfully, the documentation tools will fail at that obstacle.</p>
<p>• Undeclared in the build file external resources and related projects. If you have read <strong><a href="http://www.curiousm.com/labs/2011/04/18/creating-asdocs-with-ant-flash-builder-part-1/" target="_blank">Part 1</a></strong> of this tutorial,  you must now know about the &#8220;-source-path&#8221;, &#8220;-doc-sources&#8221;, &#8220;-external-library-path&#8221;, and my personal favorite &#8220;-exclude-classes&#8221;. Declare all external resources because they are mentioned in your project&#8217;s code and the documentation tool would look for them, but will not find them unless you specify their paths in your buildFile.xml.</p>
<p><a href="http://www.curiousm.com/labs/files/2011/04/externalPaths.png"><img class="alignnone size-full wp-image-1165" src="http://www.curiousm.com/labs/files/2011/04/thumbOfExtPaths.png" alt="" width="556" height="118" /></a></p>
<p>• Be careful where you place your build-file. You cannot modify the example build-file you will find in the Ant folder, but you can copy and customize it. I place my build-files directly in this location: /Applications/Adobe Flash Builder 4/sdks/4.1.0/ant/yourBuildFile.xml.</p>
<p>• Spark and Halo do not always mix when it comes to documentation. Below is an example of what happens when you have halo for a project theme but you have used a spark component. <a href="http://www.curiousm.com/labs/files/2011/04/Screen-shot-2011-04-21-at-3.03.47-PM.png"><img class="alignnone size-full wp-image-932" src="http://www.curiousm.com/labs/files/2011/04/Screen-shot-2011-04-21-at-3.03.47-PM-e1303478387986.png" alt="" width="570" height="63" /></a><br />
<em><span style="font-size: small">Ant build Error.</span></em></p>
<p>I will keep adding to this list every time I meet a new issue regarding documentation generation.</p>
<p>Next is <strong>Part 3</strong> of this tutorial, where I will cover template customization. This way your documentation can take on a view and feel closer to that of your project, and I promise you good presentation always pays!</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2011/04/26/creating-asdocs-with-ant-flash-builder-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating ASDocs with ANT &amp; Flash Builder Part 1. Installing Ant on Flash Builder 4.5</title>
		<link>http://www.curiousm.com/labs/2011/04/18/creating-asdocs-with-ant-flash-builder-part-1/</link>
		<comments>http://www.curiousm.com/labs/2011/04/18/creating-asdocs-with-ant-flash-builder-part-1/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 13:58:11 +0000</pubDate>
		<dc:creator>Momchilova Ralica</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[ANT]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[asdoc]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[generate]]></category>
		<category><![CDATA[standalone]]></category>
		<guid isPermaLink="false">http://www.curiousm.com/labs/?p=684</guid>
		<description><![CDATA[When creating a new application on Flash Builder 4 it’s a good dev practice to write documentation for it. Having a well organized and up to date documentation for each project can be helpful when introducing a new developer to the team, and when wrapping up a project for a client. It has also helped [...]]]></description>
			<content:encoded><![CDATA[<p>When creating a new application on Flash Builder 4 it’s a good dev practice to write documentation for it. Having a well organized and up to date documentation for each project can be helpful when introducing a new developer to the team, and when wrapping up a project for a client. It has also helped me multiple times when I have been working on big applications with multiple custom classes.</p>
<p><span id="more-684"></span></p>
<p>Keeping up and creating a well structured documentation can sometimes be just as time-consuming as writing the application itself. That is why I use the ANT plugin for Adobe® Flash Builder 4.5. It can generate documentation structure similar to the one used for the Adobe Flex Language Reference (<em>if you have used Adobe&#8217;s online Help/Docs/Manual</em>), which makes it a great ASDoc tool to have when making project documentation.</p>
<p>For clarity, I have split this post into three parts. Part one focuses on the Ant plugin installation for Adobe® Flash Builder 4.5 and how to setup an Ant build-file.xml for your documentation project. Part 2 is the actual project documentation process for Ant on standalone Flash Fuilder 4.5. Common Glossary and output. Part 3 will cover the documentation template customization.</p>
<h2>Good to know:</h2>
<p><strong>ASDoc: </strong> A command-line tool for generating API language reference documentation for your project based on specific comments that exist inside your classes.</p>
<p><strong>ANT:</strong> Ant (Another Neat Tool) is a scripting tool plugin for standalone Flash Builder 4. It helps developers by automating many tasks regarding application code management.<em> Link to ANT Manual:</em><a href="http://ant.apache.org/manual/index.html"> http://ant.apache.org/manual/index.html</a><br />
<strong>build file: </strong>This is an XML file used by Ant. Consists of tags with XML-based syntax which list targets and dependencies in a script file, which is invoked from a command prompt or (as in this case) by the Ant plugin for stndalone Flash Builder 4.5.</p>
<p><strong>Adobe® Flash Builder 4:</strong><em> Currently Adobe® Flash® Builder® 4.5 software, formerly Adobe Flex® Builder®, is an Eclipse™ based development tool for rapidly building expressive mobile, web, and desktop applications using ActionScript® and the open source Flex framework. &#8211; </em> <a href="http://www.adobe.com/products/flash-builder.html">Adobe Website / Flash Builder 4.5</a></p>
<h2><strong>1. Ant on Flash Builder.</strong></h2>
<p>If you already have integrated Ant with Flash Builder skip this part.</p>
<p><a href="http://www.curiousm.com/labs/files/2011/04/installOfAnt11-e1302892913380.png"><img class="alignnone size-full wp-image-808" src="http://www.curiousm.com/labs/files/2011/04/installOfAnt11-e1302892913380.png" alt="" width="550" height="242" /></a></p>
<div id="attachment_714" class="wp-caption alignleft" style="width: 220px"><a href="http://www.curiousm.com/labs/files/2011/04/installedAnt-e1302884570644.jpg"><img class="size-medium wp-image-744" src="http://www.curiousm.com/labs/files/2011/04/installedAnt-e1302884570644-300x129.jpg" alt="" width="210" height="90" /></a><p class="wp-caption-text">Click to Enlarge.</p></div>
<p>1. Paste URL below in the &#8216;Work with:&#8217; field. http://download.eclipse.org/releases/galileo<br />
2. Narrow your search by typing &#8216;Eclipse Java&#8217;.<br />
3. Select the Eclipse Java Development Tools check box in the list.<br />
4. Finish the installation process and restart Flash Builder.<br />
If your installation was successful you will see the the ANT view in Flash Builder&#8217;s &#8216;Other Views&#8217; menu.</p>
<h2><strong>2. Generating ASDocs with Ant.</strong></h2>
<p>Once Ant is installed on Flash Builder you can go in FB&#8217;s &#8216;External Tools Configurations&#8217; and create a new Ant  Build configuration. To get to the &#8216;External Tools Configurations&#8217; dialog select Run&gt;External Tools&gt;External Tools Configurations.</p>
<div id="attachment_765" class="wp-caption alignright" style="width: 310px"><a href="http://www.curiousm.com/labs/files/2011/04/FB_ExtToolsView.jpg"><img class="size-medium wp-image-765 " src="http://www.curiousm.com/labs/files/2011/04/FB_ExtToolsView-300x129.jpg" alt="Click to Enlarge" width="300" height="129" /></a><p class="wp-caption-text">Click to Enlarge</p></div>
<p>Next select the Ant Build configuration type and click on the &#8216;New&#8217; button (top left) to create a new Ant configuration.</p>
<p>You can give your new Ant configuration a new name by typing in the &#8216;Name&#8217; field in the configuration settings dialog.</p>
<p>The next step is to create a custom <em>build file </em>for your project and define its path in the configuration settings.</p>
<p>Ant&#8217;s <em>build-files</em> are written in XML. Each build-file must contain one project and at least one (default) target. Here is an example of a generic build-file. Tag explanations can be found <strong><a title="Apache Ant User Manual" href="http://http://ant.apache.org/manual/using.html">here</a></strong>.</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;project name=&quot;Flex Ant Tasks&quot; default=&quot;main&quot; basedir=&quot;.&quot;&gt;
    &lt;target name=&quot;main&quot; depends=&quot;clean, jar&quot; /&gt;
    &lt;target name=&quot;compile&quot;&gt;
        &lt;mkdir dir=&quot;classes&quot; /&gt;
        &lt;javac srcdir=&quot;src&quot; destdir=&quot;classes&quot;/&gt;
    &lt;/target&gt;
    &lt;target name=&quot;jar&quot; depends=&quot;compile&quot;&gt;
        &lt;jar destfile=&quot;lib/flexTasks.jar&quot;&gt;
            &lt;fileset dir=&quot;.&quot;
                     includes=&quot;flexTasks.tasks&quot; /&gt;
            &lt;fileset dir=&quot;classes&quot;
                     includes=&quot;**/*.class&quot;/&gt;
            &lt;fileset dir=&quot;.&quot;
                     includes=&quot;templates/**&quot; /&gt;
        &lt;/jar&gt;
    &lt;/target&gt;
    &lt;target name=&quot;clean&quot;&gt;
        &lt;delete dir=&quot;classes&quot; /&gt;
		&lt;delete file=&quot;lib/flexTasks.jar&quot; /&gt;
        &lt;delete&gt;
            &lt;fileset dir=&quot;src&quot; includes=&quot;**/*~&quot; defaultexcludes=&quot;false&quot; /&gt;
        &lt;/delete&gt;
    &lt;/target&gt;
	&lt;!-- - - - - - - - - - - - - - - - - -
          target: name
         - - - - - - - - - - - - - - - - - --&gt;
    &lt;target name=&quot;generateDocs&quot; description=&quot;Generate Project Documentation&quot;&gt;
    	&lt;echo&gt;Generating Docs&lt;/echo&gt;
    	&lt;exec executable=&quot;/Applications/Adobe Flash Builder 4/sdks/4.0.0/bin/asdoc&quot; failOnError=&quot;true&quot;&gt;
    		&lt;arg line=&quot;-source-path '/Users/YourUsername/Documents/Adobe Flash Builder 4/AnyExternalProjectName/src' '/Users/YourUsername/Documents/Adobe Flash Builder 4/AnyExternalProjectName/libs'&quot;/&gt;
			&lt;arg line=&quot;-doc-sources '/Users/YourUsername/Documents/Adobe Flash Builder 4/AnyExternalProjectName/src'&quot;/&gt;
			&lt;arg line=&quot;-external-library-path '/Users/YourUsername/Documents/Adobe Flash Builder 4/AnyExternalProjectName/libs'&quot;/&gt;
			&lt;arg line=&quot;-exclude-classes 'com.rng.data.customClass' 'com.rng.data.customClass2'&quot;/&gt;
			&lt;arg line=&quot;-templates-path '/Applications/Adobe Flash Builder 4/sdks/4.0.0/asdoc/CM_templates'&quot;/&gt;
			&lt;arg line=&quot;-main-title 'Project Documentation Title'&quot;/&gt;
			&lt;arg line=&quot;-output '/Users/YourUsername/Documents/Adobe Flash Builder 4/YourDocumentedProject/outputFile'&quot;/&gt;
    	&lt;/exec&gt;
    &lt;/target&gt;
&lt;/project&gt;
</pre>
<p>Depending on the complexity of the project you need to document, you might have to include other related projects and/or their resources. The <em>arguments</em> (lines 31-37 above) would give you a good example of how to  do that and more.</p>
<p>Once you have customized your build-file remember the location where you saved it and navigate or type in the path to the file in your new Ant project&#8217;s settings view. (image below)</p>
<p><img src="http://www.curiousm.com/labs/files/2011/04/antSettings.jpg" alt="" width="543" height="131" /></p>
<p>Now save your configuration settings and click on the &#8216;Targets&#8217; tab in your configuration dialog.</p>
<p><a href="http://www.curiousm.com/labs/files/2011/04/Ant_Targets.jpg"><img class="size-full wp-image-805 alignnone" src="http://www.curiousm.com/labs/files/2011/04/Ant_Targets.jpg" alt="" width="545" height="136" /></a></p>
<p>Save your settings and you done with Part 1 !</p>
<p>If you already have written out any ASDoc comments inside your Flash Builder project work-file you can click &#8216;Run&#8217; (bottom right of Configurations window). Pressing &#8216;Run&#8217; will start documentation generation and you can follow its progress in the ASDoc progress console.</p>
<p>Next Week, <a href="http://www.curiousm.com/labs/2011/04/26/creating-asdocs-with-ant-flash-builder-part-2/"><strong>Part 2</strong></a> writing ASDoc Comments, Common Errors, and Exporting.</p>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2011/04/18/creating-asdocs-with-ant-flash-builder-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Connect to LinkedIn API from AS3 and Adobe AIR</title>
		<link>http://www.curiousm.com/labs/2011/03/09/connect-to-linked-in-api-from-as3-and-adobe-air/</link>
		<comments>http://www.curiousm.com/labs/2011/03/09/connect-to-linked-in-api-from-as3-and-adobe-air/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 16:42:04 +0000</pubDate>
		<dc:creator>cmmlabs</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[desktop application]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<guid isPermaLink="false">http://curiousmindsmedia.wordpress.com/?p=586</guid>
		<description><![CDATA[For the purposes of this post however, I’d like to focus on LinkedIn’s API. Connecting to this service represents the other end of the difficulty spectrum in my opinion, and required quite a lot of tinkering to implement successfully.]]></description>
			<content:encoded><![CDATA[<p>As a Flex Developer in this day and age, you’ll undoubtedly be asked to connect an application to some social media API sooner or later. If you’ve undergone this process already, you may know that this can bring a host of difficulties and hassles. I have found that each service presents a unique set of challenges that you’ll need to overcome in order to get your application all wired up and communicating with the services’ publicly exposed methods. That being said, I’ve never had more difficulty consuming a web service from an AIR application than I recently encountered while connecting a client application to LinkedIn’s API. <span id="more-597"></span> </p>
<p>Many of the differences you’ll encounter in connecting to popular social media sites has to do with the tooling available to Flex Developers targeting the AIR runtime. Many services (Facebook, Twitter, LinkedIn to name a few) utilize OAuth 2.0 protocol for interacting with users’ data in a secure way. OAuth, in case you’re not familiar (and you will be very shortly), is “an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications”. You can read the specification at <a href="http://tools.ietf.org/html/rfc5849">http://tools.ietf.org/html/rfc5849</a> if you want to find out more.  </p>
<p>OAuth basically requires that you do the following steps in order to allow the user the opportunity to grant access to your application to manage data on his or her behalf. This is an overview of the process. We will look at the specifics of how to connect to LinkedIn in a few moments, using the following basic information as a primer (or a review depending on your level of familiarity with this process).  </p>
<p>Step 1: Register your application with the service you wish to connect to and receive a Consumer Key and Consumer Secret.  </p>
<p>Step 2: Your application makes a request to the service to authenticate a given user. Successful completion of this step will yield a Request Token.  </p>
<p>Step 3: The application redirects the user to the service’s sign-in and authorize page, where the user must agree to allow the app to make service calls on his behalf.  </p>
<p>Step 4: The application, upon receiving the consent of the user, exchanges the Request Token for an Access Token. This token consists of two Strings, the token and the token secret, and will be used to “sign” (a secretive process we’ll discuss in a moment) the API requests.  </p>
<p>Step 5: Call the resource you wish to consume (status update, personal info, etc..), using your Access Token (and a few other variables) to sign the request.  </p>
<p>There are a numerous code libraries available for connecting to the various social media. Probably the easiest to use of these is the FacebookDesktop Object, part of the com.facebook.graph package. Right out of the box, this tool makes it quite easy to connect to Facebook’s “Graph” API, abstracting most of the ugly details of the OAuth process we’ve just enumerated. This nice little kit practically does all of the work for you, and is very simple to set up and use in your desktop app. If you need to communicate with Facebook, I highly recommend this tool.  </p>
<p>For the purposes of this post however, I’d like to focus on LinkedIn’s API. Connecting to this service represents the other end of the difficulty spectrum in my opinion, and required quite a lot of tinkering to implement successfully. I have spent many hours refining this code. It is my hope that this tutorial will fill the enormous informational void on this topic, and help out some others where I had quite a lot of difficulty.  Please grab the src folder for this sample application <a title="LinkedIn Demo App Source" href="http://clients.curiousm.com/linkedin_tutorial_src/src.zip">here</a>. There are some functions in the source that are not included in the text of this tutorial, and I think it will serve you best to actually run this application while reading along.  The tools I used to connect to LinkedIn were from the same code library I used to connect to Twitter, the OAuth lib called “oauth-as3” from iotashan <a href="http://www.iotashan.com">http://www.iotashan.com</a>. You can grab the latest source for this project from the following svn location:<a href="http://oauth-as3.googlecode.com/svn/trunk/"> http://oauth-as3.googlecode.com/svn/trunk/</a>. There is also a dependency introduced when we include the iotashan packages. Go ahead and grab the as3crypto swc from the following URL <a href="http://code.google.com/p/as3crypto/downloads/detail?name=as3crypto.swc">http://code.google.com/p/as3crypto/downloads/detail?name=as3crypto.swc</a> and include that in the build path for your project. Alternatively, you can also grab the source from google code if you prefer to see what exactly is going on under the hood, as I have in the sample application.  </p>
<p>So, let’s get into the code now. Admittedly, this isn’t the most impressive application I’ve ever written (from a UI standpoint), but the control flow is what we’re concerned with here, and the functional elements are pretty straightforward and informative.  In order to run this application, you’ll need to register an application with LinkedIn to obtain your own Consumer Key and Consumer Secrets. I’ve indicated on lines 45 and 46 of my source where your Strings should be inserted to make your application unique from LinkedIn’s perspective.  The entry point for this whole handshake process is found on line 60 in the ‘post()’ function below. This is called after you enter some comment text into the field, and hit the Submit Button on the UI.</p>
<p><code><br />
private function post():void{<br />
_comment = commentArea.text;<br />
var shOb:SharedObject = SharedObject.getLocal(_sharedObName);<br />
var tmpTok:Object = shOb.data["accessToken"];<br />
_oauthConsumer = new OAuthConsumer(_consumerKey, _consumerSecret);<br />
_signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();<br />
if(tmpTok){<br />
var token:OAuthToken = new OAuthToken(tmpTok.key, tmpTok.secret);<br />
doStatusUpdate(_comment, token);<br />
} else {<br />
hiOauth_CareToDance();<br />
}<br />
}<br />
</code></p>
<p>In this function we set up some basic variables (our OAuthConsumer and OAuthSignatureMethod_HMAC_SHA1 Objects) which we’ll need for making our requests, as well as check for the possibility that we’ve already got a valid Access Token  stored in a Shared Object called ‘linkedInData.acessToken’. Let’s assume that tmpTok comes back null (line 68), and we need to go through the entire process of getting both the Request and Access Tokens from LinkedIn.  We proceed to the function called ‘hiOauth_CareToDance()’ which is the point at which we’ll be requesting the Request Token.</p>
<p><code><br />
private function hiOauth_CareToDance():void{<br />
_requestParams = generateParams(_consumerKey);<br />
_oauthReq = new OAuthRequest(_reqMeth, _requestTokenURL, _requestParams, _oauthConsumer, _token);<br />
var postData:Object = _oauthReq.buildRequest(_signatureMethod, OAuthRequest.RESULT_TYPE_POST);<br />
var urlReq:URLRequest = new URLRequest(_requestTokenURL);<br />
urlReq.method = _reqMeth;<br />
urlReq.data = postData;<br />
var loader:URLLoader = new URLLoader(urlReq);<br />
loader.addEventListener(Event.COMPLETE, onComplete);<br />
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);<br />
loader.load(urlReq);<br />
</code></p>
<p><code>function onComplete(evt:Event):void{<br />
loader.removeEventListener(Event.COMPLETE, onComplete); loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);<br />
_token = generateToken(evt.currentTarget.data);<br />
_requestParams.oauth_token = _token; authenticate(_requestParams, _token);<br />
}</p>
<p></code></p>
<p><code>function onIOError(evt:IOErrorEvent):void{<br />
trace('FAIL!');<br />
loader.removeEventListener(Event.COMPLETE, onComplete); loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);<br />
}<br />
}</code></p>
<p>You’ve seen URL Requests similar to this already, but the important thing to note here is that we want to make use of our OAuthRequest Object to create the data we’ll add to the URLRequest’s ‘data’ property to send along in our POST Request. I’ve passed a few variables into the constructor of this Object to set it up, and called the instance’s buildRequest method to get back an Object containing everything LinkedIn wants to see in order to issue us a Request Token. On Event.COMPLETE we move on to the function called ‘authenticate’ after adding our token (_token) to _requestParams.oauth_token. I’ve created a convenient little utility to parse the returned data from this request and turn it into an OAuthToken Object. This function is called ‘generateToken’.  In the ‘authenticate’ method we’re navigating to LinkedIn’s authentication URL, which allows the user to grant our application control to access and manipulate personal data on the user’s behalf. We also pop up a little window which gives the user a text input into which he or she will enter the 5 digit PIN number that LinkedIn’s authenticate window will supply us with. This function is called ‘popAuthWindow’.</p>
<p><code><br />
private function authenticate(params:Object, token:OAuthToken):void{<br />
var getReq:URLRequest = new URLRequest(_authenticateURL + '?oauth_token=' + token.key); navigateToURL(getReq, '_blank');<br />
popAuthWindow();<br />
}</code></p>
<p>PopAuthWindow is really quite basic as well, but the one thing to notice here is that I’ve set a variable called ‘submitCallbackFunc’ to a function called ‘authenticateCallbackFunc’ which will get called when the user clicks the ‘submit’ button in the popup window. I find this to be a little easier and more straightforward than creating a custom event for communicating between the popup and the main application, but you may have your own opinion about the cleanest way to accomplish this. This function will accept the pin number. Let’s look at this function now.</p>
<p><code><br />
private function authenticateCallbackFunc(pin:String):void{<br />
_requestParams.oauth_verifier = pin;<br />
var authReq:OAuthRequest = new OAuthRequest(_reqMeth, _accessTokenURL, _requestParams, _oauthConsumer, _token);<br />
var postData:Object = authReq.buildRequest(_signatureMethod, OAuthRequest.RESULT_TYPE_POST);<br />
var urlReq:URLRequest = new URLRequest(_accessTokenURL);<br />
urlReq.method = _reqMeth;<br />
urlReq.data = postData;<br />
var loader:URLLoader = new URLLoader(urlReq);<br />
loader.addEventListener(Event.COMPLETE, onComplete);<br />
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);<br />
loader.load(urlReq);<br />
</code></p>
<p><code>function onComplete(evt:Event):void{<br />
loader.removeEventListener(Event.COMPLETE, onComplete); loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);<br />
_token = generateToken(evt.currentTarget.data);<br />
_requestParams.oauth_token = _token.key;<br />
_requestParams.oauth_token_secret = _token.secret;<br />
var so:SharedObject = SharedObject.getLocal(_sharedObName);<br />
so.data["accessToken"] = _token;<br />
so.flush();<br />
doStatusUpdate(_comment, _token);<br />
}</p>
<p></code></p>
<p><code>function onIOError(evt:IOErrorEvent):void{<br />
trace('FAIL!');<br />
loader.removeEventListener(Event.COMPLETE, onComplete); loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);<br />
}<br />
}</code></p>
<p>This looks an awful lot like the ‘hiOauth_CareToDance’ function we’ve already discussed, but were the ‘_token’ variable was null before (we hadn’t yet gotten our Request Token) we are now going to have the data returned from our call to the Request Token resource. In this step, we are ostensibly trading the Request Token for an Access Token. We make use of our handy OAuthRequest Object once again to put together the variables and the signature needed to gain access to LinedIn’s Access Token resource, and populate the URLRequest’s data property with our return from the buildRequest method. On our Complete Event, we will again be given another bit of data from which we can parse our ‘oauth_token’ and ‘oauth_token_secret’.  At this point we have been fully authenticated, and have everything we need to call the actual API resources we might wish to utilize in our application. So, knowing this we can finally call the status update resource, and submit our comments we had typed into our comments text input. We do this in the ‘doStatusUpdate’ method.</p>
<p><code><br />
private function doStatusUpdate(comment:String, tok:OAuthToken):void{<br />
if(!_requestParams){<br />
_requestParams = generateParams(_consumerKey);<br />
delete _requestParams.oauth_token_secret;<br />
delete _requestParams.oauth_verifier;<br />
var oauthGen:OAuthRequest = new OAuthRequest(_reqMeth, _statusUpdateURL, _requestParams, _oauthConsumer, tok);<br />
var header:URLRequestHeader = oauthGen.buildRequest(_signatureMethod, OAuthRequest.RESULT_TYPE_HEADER);<br />
var urlReq:URLRequest = new URLRequest(_statusUpdateURL);<br />
urlReq.method = _reqMeth;<br />
urlReq.requestHeaders.push(header);<br />
urlReq.contentType = 'text/xml';<br />
urlReq.data = generateLinkedInStatusXML(comment);<br />
var loader:URLLoader = new URLLoader(urlReq);<br />
loader.addEventListener(Event.COMPLETE, onComplete);<br />
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);<br />
loader.load(urlReq);  </p>
<p>function onComplete(evt:Event):void{<br />
Alert.show("Your status message was successfully sent.", "Linked In Status Updated!" );<br />
}</p>
<p>function onIOError(evt:IOErrorEvent):void{<br />
// if we hit this.. our token must be expired..<br />
hiOauth_CareToDance();<br />
}<br />
}<br />
</code></p>
<p>We see some familiar elements in this, such as the OAuthRequest and the URLRequest variables, but you’ll also notice that we have introduced a URLRequestHeader in this function which we did not have previously. The reason for this is that we are now transmitting two necessary pieces of data over the wire, not just one. We have to supply our Access Token so that we can demonstrate to LinkedIn’s servers that we are legit, but we also want to send some data to update our status at the same time. This was a little tricky for me to figure out, so I’m hoping that this demo makes even one developer’s life a little easier (ten would be even better). In order to do this, we will again build the OAuth signature with the OAuthRequest, but since we are going to want to use the data property of our URLRequest for the status update XML, we need to change the mode of our OAuthRequest to OAuthRequest.RESULT_TYPE_HEADER. You’ll notice this on line 89 of the sample application. When we change the request type to header, we get back a URLRequestHeader instead of a generic Object. This we can then push into our requestHeaders array. LinkedIn is able to deal with this accordingly, and will verify the validity of this request based on the header, and not the data of our request as we had done previously.  As for the data in this step (the actual status comment), I have created a very basic ‘generateLinkedInStatusXML’ function which creates the most basic status update markup from our comment input text. You can do more with this data if you so desire. Please refer to the LinkedIn API reference pages for more information on this. </p>
<p>In addition, make sure you set the content type of your URLRequest to ‘text/xml’ or you will not have success in making this call (yet another trap I fell into during this arduous process).  There are also 2 lines of code deleting certain items from the _requestParams data before we make this request. These 2 variables were necessary in previous steps of the OAuth authentication process, but which we no longer need now that we have the Access Token. Don’t pay too much attention to these. I believe you can leave those intact, and it will have zero effect on the success of this call.  </p>
<p>OK, with a little bit of luck this request will come back successfully and our application will alert us to the fact that our status has been updated. Hop on over to your LinkedIn profile and verify that the message did make it onto your wall (or whatever they call it in LinkedIn parlance).  </p>
<p>Congratulations! You have just successfully navigated the tedious OAuth handshake, and are now able to build out a more useful and full featured application based on this new knowledge.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2011/03/09/connect-to-linked-in-api-from-as3-and-adobe-air/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Flash Builder 4 beta Released</title>
		<link>http://www.curiousm.com/labs/2009/06/09/flash-builder-4-beta-released/</link>
		<comments>http://www.curiousm.com/labs/2009/06/09/flash-builder-4-beta-released/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 15:05:47 +0000</pubDate>
		<dc:creator>cmmlabs</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[Apollo]]></category>
		<category><![CDATA[Company]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flash Catalyst]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>
		<guid isPermaLink="false">http://curiousmindsmedia.wordpress.com/?p=433</guid>
		<description><![CDATA[We had been waiting in eager anticipation through the first half of this year for it to finally arrive. All indications were that we would be well adjusted to our new work flow by the time summer rolled around for sure, enjoying all the new tooling and features of Flex 4...]]></description>
			<content:encoded><![CDATA[<p>We had been waiting in eager anticipation through the first half of this year for it to finally arrive. All indications were that we would be well adjusted to our new work flow by the time summer rolled around for sure, enjoying all the new tooling and features of Flex 4, round tripping some super-duper new skins with our design team via Catalyst, and improving our productivity on the whole. But as winter gave way to spring, our excitement began to wane until I had all but forgotten about the coming of this new generation of Flex. When suddenly, with almost no warning whatsoever, it was upon us&#8230; the new Flash Builder 4 beta, code named &#8216;Gumbo&#8217;.</p>
<p><span id="more-433"></span></p>
<p>Adobe&#8217;s newest attempt at reconciling its past branding snafus, is to name their new flagship IDE &#8216;Flash Builder&#8217; which for me just seemed like a bad mashup of its progenitors&#8217; names. And this at a time when the development community had fully embraced the Flex application paradigm and branding, and to a great extent, so had the better informed end users of Flex applications. I personally thought that Flex Builder had a much more appealing ring to it as well, but hey, that&#8217;s just my personal opinion.</p>
<p>But how easy it is to be critical, and from what I can tell (despite the obligatory growing pains) this release is going to be a great big step forward for our team. Allow me to elaborate some..</p>
<p>We at curious minds have recently been working on some pretty snazzy AIR apps over the last few months, and in the process gotten very adept at skinning our components and integrating our designers&#8217; work quickly and effectively. (There are a few of our  blog posts relating to these topics that are quite informative if you are interested). According to Adobe, Catalyst is going to give us even more flexibility (not a pun) and better integration than before. Our designers are going to be able to create Flex apps directly in Catalyst, and our developers can import them and get down to business integrating the UIs with data and application logic. Finally, we&#8217;ll actually be able to work in the same environment, and on the same app simultaneously! I know that for certain developers (myself very much included), this is going to make life a great deal easier, allowing us to focus on the things that we are actually good at doing. This is probably the best feature of Catalyst as I see it. The fact that the work will now flow both directions between designers and developers, instead of the &#8216;uni-directional&#8217; limitation that seems to pervade our current system.</p>
<p>Another feature that I&#8217;m completely gaga over in &#8216;Gumbo,&#8217; is the integrated network traffic monitor. What a huge help this tool is going to be in the development/debugging process! With inline tree views of XML and AMF server response data, this HTTP monitor is going to cut a lot of the nasty trace style debugging right out. Also, being able to jump directly to the line in your code that originated the RPC request is a great feature of this tool.</p>
<p>All in all, I am really excited about diving into the new IDE. I&#8217;ll post up a full report once we get a little better situated with our new software, and as always, look for great tutorials on the new generation of Adobe design/development tools.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2009/06/09/flash-builder-4-beta-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedding Irregular Fonts in Flex 3</title>
		<link>http://www.curiousm.com/labs/2009/06/04/embedding-irregular-fonts-in-flex-3/</link>
		<comments>http://www.curiousm.com/labs/2009/06/04/embedding-irregular-fonts-in-flex-3/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 00:28:27 +0000</pubDate>
		<dc:creator>cmmlabs</dc:creator>
				<category><![CDATA[air]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Graphic Design]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<guid isPermaLink="false">http://curiousmindsmedia.wordpress.com/?p=426</guid>
		<description><![CDATA[Often in programming, what seems to be a simple task can trip you up. Yesterday I was trying to embed the font Helvetic Neue LT Com Bold 77 in a css style sheet for a project of ours. After about 20 minutes of trying different methods to get the project to compile without any errors, [...]]]></description>
			<content:encoded><![CDATA[<p>Often in programming, what seems to be a simple task can trip you up. Yesterday I was trying to embed the font Helvetic Neue LT Com Bold 77 in a css style sheet for a project of ours. After about 20 minutes of trying different methods to get the project to compile without any errors, I came across the following method:<span id="more-426"></span>It turns out that with a font like the Bold 77, The typeface is already bold, so there is no need to put the fontStyle:Bold directive in the css declaration. In fact, since 77 bold already contains no bold style, and declaring it as such will throw an error. </p>
<p>Font Book on mac is a great app. Using the app&#8217;s ability to intropect on the font, you can see all of the information in each font on your computer. The most important information you can get out of Font Book is the full font name attribute. The key here is to embed the full font name attribute in the flex application. Just like this:</p>
<p>@font-face<br />
{<br />
     src: url(&#8216;path/to/embed.swf&#8217;);<br />
     fontFamily:&#8221;Helvetic Neue LT Com Bold 77&#8243;;<br />
} </p>
<p>The important thing here is that if you arre unsure of what font faces are included in any particular font, just use the full font name alone, and dont mess with anything else. </p>
<p>For Flex Builder 3 apps, we like to use the Flash Embed method of getting the font transcoded into the Flex App. The resulting file size is much lower. Just be sure to embed only the characters that you are going to need, and not the entire set.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2009/06/04/embedding-irregular-fonts-in-flex-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using the Factory Method Pattern</title>
		<link>http://www.curiousm.com/labs/2009/05/07/using-the-factory-method-pattern/</link>
		<comments>http://www.curiousm.com/labs/2009/05/07/using-the-factory-method-pattern/#comments</comments>
		<pubDate>Thu, 07 May 2009 19:22:13 +0000</pubDate>
		<dc:creator>cmmlabs</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[Apollo]]></category>
		<category><![CDATA[Design Process]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[factory class]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[mxml]]></category>
		<guid isPermaLink="false">http://curiousmindsmedia.wordpress.com/?p=351</guid>
		<description><![CDATA[ Introduction to a Classic OOP Design Pattern Throughout my career as a developer I have had the occasion to use the Factory Method Pattern when appropriate, and grown to rely on it extensively in recent months as several projects have dictated. I find this pattern to be extremely useful in creating a loosely-coupled application architecture, [...]]]></description>
			<content:encoded><![CDATA[<p> Introduction to a Classic OOP Design Pattern</p>
<p>Throughout my career as a developer I have had the occasion to use the Factory Method Pattern when appropriate, and grown to rely on it extensively in recent months as several projects have dictated. I find this pattern to be extremely useful in creating a loosely-coupled application architecture, which (as we&#8217;ve all been indoctrinated) is the cornerstone of well designed apps. It is my hope that this introduction will illuminate this pattern for the uninitiated. Even if you don&#8217;t find an immediate application for the Factory Pattern, just understanding the &#8216;why&#8217; and &#8216;how&#8217; of this design can be important in grasping the importance of the &#8220;open-closed&#8221; principle, and will help you to write better code. </p>
<p>Let me start off by giving the standard text-book definition of the pattern:</p>
<p>The Factory Pattern &#8220;&#8230;define[s] an interface for creating an object, but allows the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses.&#8221; </p>
<p><span id="more-351"></span></p>
<p>Chances are that many readers out there will be quite familiar this manner of verbiage. However if you need a quick primer, this more or less states that this pattern can be used when you have the need to create objects of a varying types, and whose types cannot be known before runtime. One quick aside, I&#8217;m going to call these objects &#8216;products&#8217; as real life factories generally produce things called products, and it is always useful when dealing with abstractions to think in more concrete terms. The situation I&#8217;ve just described is common if the product you need to create depends on configuration settings, or more likely, responses to user interaction. </p>
<p>Let&#8217;s step through a likely code example together to light a proverbial fire under this otherwise sterile illustration. I&#8217;ve chosen a product that I&#8217;m currently pretty enthused about&#8230; guitars. Now everybody knows that there are about int.MAX_VALUE types of guitars in the world, and any guitar player will tell you that you can never have too many of the darn things around. So it wouldn&#8217;t be a stretch to envision an app that queries a customer for his/her desired guitar characteristics, makes up a request for said guitar, and sends it off to a guitar factory object to do the construction of the desired guitar object, right? A superlative example if I do say so. </p>
<p>For the sake of simplicity, we&#8217;re going to limit the types of guitars available to the user to &#8216;electric&#8217;, &#8216;acoustic steel-string&#8217;, and  &#8217;acoustic nylon-string&#8217;, each of these types having unique properties, and the inherent need to be constructed in different ways. They are all guitars, however, and thus share certain properties common to all guitars. We can logically represent this commonality by defining an interface called IGuitar. IGuitar might look similar to the following:</p>
<p>public interface IGuitar{<br />
<span> </span>function lookPretty():void;<br />
<span> </span>function soundIncredible():AwestruckListener;<br />
}</p>
<p>These are all of the things that our guitars need to be able to do, else we call them canoe paddles, or bits of kindling, or perhaps worse. Each guitar class that implements this interface is responsible for providing the necessary details about how it does &#8216;lookPretty&#8217; and &#8216;soundIncredible.&#8217; Now, you might ask how we are going to build all of these different types of guitar in one factory. The key to this trick is all in the implementation of the IGuitar Interface. Here is our GuitarFactory code:</p>
<p>public class GuitarFactory {<br />
    public static function buildGuitar(guitarType:String):IGuitar {<br />
  <span> </span>   switch(guitarType) {<br />
            case &#8216;electric&#8217;:<br />
                return new ElectricGuitar();<br />
<span> </span>                break;<span> </span><br />
            case &#8216;acoustic steel_string&#8217;:<br />
                return new AcousticSteelStringGuitar();<br />
<span> </span>                break;<span> </span><br />
            case &#8216;acoustic nylon_string&#8217;:<br />
<span> </span>                return new AcousticNylonStringGuitar();<br />
<span> </span>                 break;<br />
<span> </span>                  default:<br />
<span> </span>                        trace(guitarType + &#8216; ain&#8217;t no guitar I&#8217;ve ever heard of.&#8217;);<br />
              }<br />
        }<br />
}</p>
<p>You&#8217;ll notice that the buildGuitar method returns an instance of IGuitar, which gives us the flexibility to return any type of object that has implemented that interface. This is crucial if we intend to add more and varied types of guitars to our custom guitar shop application. For instance, we could easily add bass-guitars, balalaikas, cavaqhinhos, or any other instrument that has agreed to meet the requirements set forth in the interface. </p>
<p> </p>
<p>This example is perhaps a bit pedestrian, if not corny, but you get the idea. The main point to take away from this is the idea that you can defer creation of a given type of object until it becomes necessary to build it. This gives you a great deal of flexibility in your application, and can be extremely handy in a host of situations. Check it out for yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2009/05/07/using-the-factory-method-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Tutorial &#8211; The Singleton Pattern</title>
		<link>http://www.curiousm.com/labs/2009/05/07/as3-tutorial-the-singleton-pattern/</link>
		<comments>http://www.curiousm.com/labs/2009/05/07/as3-tutorial-the-singleton-pattern/#comments</comments>
		<pubDate>Thu, 07 May 2009 15:56:55 +0000</pubDate>
		<dc:creator>cmmlabs</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[Apollo]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Object Oriented]]></category>
		<category><![CDATA[Singleton]]></category>
		<guid isPermaLink="false">http://curiousmindsmedia.wordpress.com/?p=238</guid>
		<description><![CDATA[One of the most important patterns that we use over here is the Singleton. It&#8217;s used when you need to restrict use of a class to one or only one instance. This comes in handy when you are casting things like application wide settings, or if you are building something like a logging service. There [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most important patterns that we use over here is the Singleton. It&#8217;s used when you need to restrict use of a class to one or only one instance. This comes in handy when you are casting things like application wide settings, or if you are building something like a logging service. There is a bit of disagreement on the use of the singleton, but it really boils down to two questions:</p>
<p><span id="more-238"></span></p>
<ul>
<li>Will you use this class <strong>exactly</strong> the same way?</li>
<li>Will you only <strong>ever</strong> need <strong>only</strong> one instance of this class?</li>
</ul>
<p>If you answer yes to these two questions, you might have the case to build a singleton. &#8211; So here is how you go about doing it in AS3 -it&#8217;s a bit tricksy &#8217;cause as3 has no private constructors:</p>
<p>&nbsp;</p>
<p>Example Singleton</p>
<pre class="brush: as3; title: ; notranslate">
package somepackage{
public class MySingleton{
private static var _instance:MySingleton;
public function MySingleton(enforcer:Enforcer){}
public static function getInstance():mySingleton{
if(MySingleton._instance==null){
MySingleton._instance = new MySingleton(new Enforcer)}
return MySingleton._instance
}
public function someExampleService():void{}
}
}
class Enforcer{}
</pre>
<p>So that&#8217;s the basic code structure. Some items of note is the inclusion of the empty Enforcer class <em>outside</em> of the package. This is critical, as you don&#8217;t want to place your Enforcer in the package or class definition of the singleton. So lets talk about how this thing works. The key is the conditional static function getInstance. It only creates the internal variable _instance if one does not already exist. In addition to this restriction, the Enforcer class will generate an error if you try to instantiate  an instance of MySingleton using the <span style="color: #3366ff;">new</span> keyword. Try it&#8230;</p>
<p>Great&#8230;So how do you instantiate this pattern? Simple&#8230; just access the class methods through the getInstance() method:</p>
<p>MySingleton.getInstance().someExampleService()</p>
<p>&nbsp;</p>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.curiousm.com/labs/2009/05/07/as3-tutorial-the-singleton-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
