<?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>zedia flash blog &#187; Robotlegs</title>
	<atom:link href="http://www.zedia.net/tag/robotlegs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zedia.net</link>
	<description>Flash, ActionScript, SEO and everything in between</description>
	<lastBuildDate>Wed, 21 Jul 2010 17:07:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Drawing Bezier tool using Robotlegs</title>
		<link>http://www.zedia.net/2010/drawing-bezier-tool-using-robotlegs/</link>
		<comments>http://www.zedia.net/2010/drawing-bezier-tool-using-robotlegs/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 04:05:01 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[bezier]]></category>
		<category><![CDATA[FITC]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=651</guid>
		<description><![CDATA[I came back from FITC Toronto with a lot of ideas for new posts and this is the last one of them. But fear not this is a first article in what will probably be a serie of 3 because it would otherwise be too long (or I wouldn&#8217;t have the patience to write it). [...]]]></description>
			<content:encoded><![CDATA[<p>I came back from <a title="FITC" href="http://www.fitc.ca">FITC Toronto</a> with a lot of ideas for new posts and this is the last one of them. But fear not this is a first article in what will probably be a serie of 3 because it would otherwise be too long (or I wouldn&#8217;t have the patience to write it). So while at FITC, I went to a presentation be the guys at Firstborn about how they were often making tools instead of doing things by brute force. Well the idea stuck with me.</p>
<p>In the current project that I am working on, there was a part where I needed the coordinates of points along a path. The brute force way was to estimate the next point myself and to compile to see if I was right, repeat until I had all the coordinates I needed. Very tedious and boring task and the path could change often so there was high chances that I would redo this process often. What better time to start making a tool! Well it turn out that my project changed so much that that part wasn&#8217;t in it anymore&#8230; But it still makes a great topic for this blog.</p>
<p>Let me start by showing you what will be the result of this first post. (Below is not juste whitespace, click in it to ad points. You can select a path to make a control point appear, drag the control point to make a curve).</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.zedia.net/flash/Main.swf" /><embed type="application/x-shockwave-flash" width="550" height="400" src="http://www.zedia.net/flash/Main.swf"></embed></object></p>
<p>As you can see this is pretty bare bone. But the good thing about that is that you can use this as the base of multiple tools.</p>
<p>I built this using <a title="Robotlegs" href="http://www.robotlegs.org">Robotlegs</a>. If I am going to build something for myself, might as well learn (or train) a few things on the way. Plus, I think Robotlegs is very well suited for application style projects. Now that being said, using that kind of framework (MVC) will require you to create a lot of extra classes but in the end you will understand what you gain by doing so. Out of all these, 4 of them are really important. The Model, where you will keep all information on paths and points at all time and three View classes; one for the clickable area layer, one for the paths layer and one for the point layer.</p>
<p>The easiest of all of them is the clickable are layer. It&#8217;s job is just to register clicks and tell the framework where something has been clicked. This could have been done otherwise, but since we will want to layer stuff (points are over paths) plus we will want to select points and path to move or curve them, it is just easier to create a view just to register clicks on the unused stage and put that view in the back off our application.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">view</span>.<span style="color: #006600;">components</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">PointEvent</span>;
  <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">objects</span>.<span style="color: #006600;">PointObject</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
    * @author dominicg
  */</span>
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DrawingArea <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> pointArray:<span style="color: #0066CC;">Array</span>;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _pathArray:<span style="color: #0066CC;">Array</span>;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> DrawingArea<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      graphics.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xffffff<span style="color: #66cc66;">&#41;</span>;
      graphics.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">550</span>, <span style="color: #cc66cc;">400</span><span style="color: #66cc66;">&#41;</span>;
      graphics.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      addEventListener<span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, _onMouseClick, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onMouseClick<span style="color: #66cc66;">&#40;</span>event : MouseEvent<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
      dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PointEvent<span style="color: #66cc66;">&#40;</span>PointEvent.<span style="color: #006600;">ADD_POINT</span>, <span style="color: #000000; font-weight: bold;">new</span> PointObject<span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">stageX</span>, event.<span style="color: #006600;">stageY</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Our second view is the one that handles the points. Points are simple visual objects, they are just circles placed at a x and y coordinate. So when the user clicks on the clickable layer, the point view is notified and a circle is added where the click was registered. Another functionality that is added is that you can drag a point to move it around the stage. One thing to notice is that whenever a point is moved, it tells the framework about it so that the Model is always up to date and so that the path layer can display the paths correctly.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">view</span>.<span style="color: #006600;">components</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">PointEvent</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">objects</span>.<span style="color: #006600;">PointObject</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * @author dominicg
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PointLayer <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _pointVector:Vector.<span style="color: #66cc66;">&lt;</span>PathPoint<span style="color: #66cc66;">&gt;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PointLayer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			_pointVector = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>PathPoint<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addPoint<span style="color: #66cc66;">&#40;</span>point:PointObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> pathPoint:PathPoint = <span style="color: #000000; font-weight: bold;">new</span> PathPoint<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			pathPoint.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>PointEvent.<span style="color: #006600;">POINT_MOVED</span>, _onPointMoved, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			pathPoint.<span style="color: #006600;">x</span> = point.<span style="color: #006600;">x</span>;
			pathPoint.<span style="color: #006600;">y</span> = point.<span style="color: #006600;">y</span>;
			addChild<span style="color: #66cc66;">&#40;</span>pathPoint<span style="color: #66cc66;">&#41;</span>;
			_pointVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>pathPoint<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onPointMoved<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PointEvent<span style="color: #66cc66;">&#40;</span>PointEvent.<span style="color: #006600;">POINT_MOVED</span>, <span style="color: #000000; font-weight: bold;">new</span> PointObject<span style="color: #66cc66;">&#40;</span>PathPoint<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">x</span>, PathPoint<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">y</span>, _pointVector.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>PathPoint<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now this is the last of the view class: the PathLayer. It is also the most complicated of the three view classes because a path is a complex object. It is comprised of a start point, an end point and a control point. With those you can draw a curve using the curveTo method from the AS3 drawing API. Here is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">view</span>.<span style="color: #006600;">components</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">PathEvent</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">objects</span>.<span style="color: #006600;">PointObject</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">objects</span>.<span style="color: #006600;">PathObject</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * @author dominicg
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PathLayer <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _pathVector:Vector.<span style="color: #66cc66;">&lt;</span>Path<span style="color: #66cc66;">&gt;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _selected:<span style="color: #0066CC;">int</span> = -<span style="color: #cc66cc;">1</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PathLayer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			_pathVector = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>Path<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addPath<span style="color: #66cc66;">&#40;</span>pathObject:PathObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> path:Path = <span style="color: #000000; font-weight: bold;">new</span> Path<span style="color: #66cc66;">&#40;</span>pathObject.<span style="color: #006600;">firstPoint</span>, pathObject.<span style="color: #006600;">secondPoint</span>, pathObject.<span style="color: #006600;">controlPoint</span><span style="color: #66cc66;">&#41;</span>;
			path.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>PathEvent.<span style="color: #006600;">PATH_CLICKED</span>, _onPathClicked, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			path.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>PathEvent.<span style="color: #006600;">CONTROL_POINT_MOVED</span>, _onControlPointMoved, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>path<span style="color: #66cc66;">&#41;</span>;
			_pathVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>path<span style="color: #66cc66;">&#41;</span>;	
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onControlPointMoved<span style="color: #66cc66;">&#40;</span>event : Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PathEvent<span style="color: #66cc66;">&#40;</span>PathEvent.<span style="color: #006600;">CONTROL_POINT_MOVED</span>, <span style="color: #000000; font-weight: bold;">new</span> PathObject<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PointObject<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> PointObject<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>, _pathVector.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Path<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>, Path<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">controlPoint</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onPathClicked<span style="color: #66cc66;">&#40;</span>event : Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_selected <span style="color: #66cc66;">&gt;</span> -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				_pathVector<span style="color: #66cc66;">&#91;</span>_selected<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">deselect</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			_selected = _pathVector.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Path<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> updatePaths<span style="color: #66cc66;">&#40;</span>updatedPathVector : Vector.<span style="color: #66cc66;">&lt;</span>PathObject<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> updatedPathVector.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_pathVector<span style="color: #66cc66;">&#91;</span>updatedPathVector<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">update</span><span style="color: #66cc66;">&#40;</span>updatedPathVector<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deselectAll<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_selected <span style="color: #66cc66;">&gt;</span> -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				_pathVector<span style="color: #66cc66;">&#91;</span>_selected<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">deselect</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				_selected = -<span style="color: #cc66cc;">1</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>You will find more information about paths in the Path class inside the view folder.</p>
<p>Finally the last important class is the Model. This is where you keep information about the state of the application. With the information stored in the Model you can recreate exactly how the application is right now, which is really practical if you want to save the state to a file or export data. As you will see, it is mostly saving a data representation of visual objects in our views (points and paths).</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">model</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">PathEvent</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">PointEvent</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">PathVectorEvent</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">objects</span>.<span style="color: #006600;">PathObject</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">drawingtool</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">objects</span>.<span style="color: #006600;">PointObject</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">robotlegs</span>.<span style="color: #006600;">mvcs</span>.<span style="color: #006600;">Actor</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Point</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * @author dominicg
	 */</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DrawingModel <span style="color: #0066CC;">extends</span> Actor <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _pointVector:Vector.<span style="color: #66cc66;">&lt;</span>PointObject<span style="color: #66cc66;">&gt;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _pathVector:Vector.<span style="color: #66cc66;">&lt;</span>PathObject<span style="color: #66cc66;">&gt;</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> DrawingModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			_pointVector = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>PointObject<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_pathVector = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>PathObject<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addPoint<span style="color: #66cc66;">&#40;</span>point:PointObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
			point.<span style="color: #006600;">id</span> = _pointVector.<span style="color: #0066CC;">length</span>;
			_pointVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>point<span style="color: #66cc66;">&#41;</span>;
			dispatch<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PointEvent<span style="color: #66cc66;">&#40;</span>PointEvent.<span style="color: #006600;">ADD_POINT_APPROVED</span>, point<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> pointLength : <span style="color: #0066CC;">int</span> = _pointVector.<span style="color: #0066CC;">length</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_pointVector.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> controlPoint:Point = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>_pointVector<span style="color: #66cc66;">&#91;</span>pointLength - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span> - _pointVector<span style="color: #66cc66;">&#91;</span>pointLength - <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span>, <span style="color: #66cc66;">&#40;</span>_pointVector<span style="color: #66cc66;">&#91;</span>pointLength - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span>- _pointVector<span style="color: #66cc66;">&#91;</span>pointLength - <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
				_pathVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PathObject<span style="color: #66cc66;">&#40;</span>_pointVector<span style="color: #66cc66;">&#91;</span>pointLength - <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>, _pointVector<span style="color: #66cc66;">&#91;</span>pointLength - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>, _pathVector.<span style="color: #0066CC;">length</span>, controlPoint<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
				dispatch<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PathEvent<span style="color: #66cc66;">&#40;</span>PathEvent.<span style="color: #006600;">ADD_PATH_APPROVED</span>, _pathVector<span style="color: #66cc66;">&#91;</span>_pathVector.<span style="color: #0066CC;">length</span> -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> updatePoint<span style="color: #66cc66;">&#40;</span>point : PointObject<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">trace</span> <span style="color: #66cc66;">&#40;</span>point.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#41;</span>;
			_pointVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">x</span> = point.<span style="color: #006600;">x</span>;
			_pointVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">y</span> = point.<span style="color: #006600;">y</span>;
			<span style="color: #808080; font-style: italic;">//Update paths now</span>
			<span style="color: #000000; font-weight: bold;">var</span> resultingPathVector:Vector.<span style="color: #66cc66;">&lt;</span>PathObject<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>PathObject<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>point.<span style="color: #006600;">id</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				_pathVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">firstPoint</span> = point;
				resultingPathVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>_pathVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>point.<span style="color: #006600;">id</span> == _pointVector.<span style="color: #0066CC;">length</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>				
				_pathVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">secondPoint</span> = point;
				resultingPathVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>_pathVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;				
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
				_pathVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">firstPoint</span> = point;
				resultingPathVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>_pathVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				_pathVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">secondPoint</span> = point;
				resultingPathVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>_pathVector<span style="color: #66cc66;">&#91;</span>point.<span style="color: #006600;">id</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			dispatch<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PathVectorEvent<span style="color: #66cc66;">&#40;</span>PathVectorEvent.<span style="color: #006600;">UPDATE_PATHS</span>, resultingPathVector<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> updateControlPoint<span style="color: #66cc66;">&#40;</span>path : PathObject<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			_pathVector<span style="color: #66cc66;">&#91;</span>path.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">controlPoint</span> = path.<span style="color: #006600;">controlPoint</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Well that is it for now. You can download the source code below and see the classes that I didn&#8217;t talk about. This is all good but this tool right now just draw paths but it doesn&#8217;t transform or export the data in any way. This will be the topic of a next post.</p>
<p><a href="http://www.zedia.net/wp-content/uploads/2010/06/ZediaBezierTool.zip">ZediaBezierTool</a></p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fdrawing-bezier-tool-using-robotlegs%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/drawing-bezier-tool-using-robotlegs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Realisation from Flash and the City</title>
		<link>http://www.zedia.net/2010/realisation-from-flash-and-the-city/</link>
		<comments>http://www.zedia.net/2010/realisation-from-flash-and-the-city/#comments</comments>
		<pubDate>Tue, 18 May 2010 15:44:23 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[FATC]]></category>
		<category><![CDATA[FITC]]></category>
		<category><![CDATA[Flash and the City]]></category>
		<category><![CDATA[Gaia]]></category>
		<category><![CDATA[Jesse Freeman]]></category>
		<category><![CDATA[Jesse Warden]]></category>
		<category><![CDATA[Robotlegs]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=637</guid>
		<description><![CDATA[First, I want to say that Flash and the City was a very well organized conference. Sure it isn&#8217;t as perfect as FITC (I know it does no justice to compare a 10 years old conference to a new one, but it&#8217;s the only other conference I have been to) but it was nonetheless amazing [...]]]></description>
			<content:encoded><![CDATA[<p>First, I want to say that <a title="Flash and the city" href="http://www.flashandthecity.com" target="_blank">Flash and the City</a> was a very well organized conference. Sure it isn&#8217;t as perfect as <a title="FITC" href="http://www.fitc.ca" target="_blank">FITC</a> (I know it does no justice to compare a 10 years old conference to a new one, but it&#8217;s the only other conference I have been to) but it was nonetheless amazing for a first year and we have Elad Elrom and his team to thank for that.</p>
<div class="wp-caption aligncenter" style="width: 410px"><img title="Flash and the City" src="http://blog.flashandthecity.com/wp-content/uploads/banners/400x150.gif" alt="" width="400" height="150" /><p class="wp-caption-text">Flash and the City</p></div>
<p>What I think they can improve on next year is the venue; the 3 legged dog was too small to hold this kind of event. I would suggest changing for a new place. What I really liked: that the speakers where different from the speakers on the other conferences roasters (seems like it&#8217;s all the same people speaking from conferences to conferences) so I got to see people I had not seen yet.</p>
<h3>The realisation</h3>
<p>I consider myself a developer and FATC was really more aimed towards developers, so I should have been very happy there. The thing is, I wasn&#8217;t; it didn&#8217;t have the same impact as FITC did on me, which is weird. I don&#8217;t know, maybe it is because I follow a lot what is happening in the Flash community and I am well informed on the new possibilities the platform has technically. Because of that, the presentations didn&#8217;t marvel me as much as a creative presentations where everything is mostly new. Maybe I am not so much a developer after all.</p>
<h3>Best of show</h3>
<p>Anyway there was still some presentations that I found really amazing. The best one that I saw really was Gaia Flash Framework by <a title="Jesse Warden" href="http://jessewarden.com/" target="_blank">Jesse Warden</a>. He spoke about using <a title="Gaia Framework" href="http://www.gaiaflashframework.com/" target="_blank">Gaia</a> and <a title="Robotlegs" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> together. I mostly knew what he was speaking about but it still was awesome. I wish I could see it again in slow motion because there are so many words that come out of Jesse&#8217;s mouth. What is the major point of interest is Jesse&#8217;s views on the industry and the way he express them. If you get the chance to see him speak don&#8217;t miss it. Well, he started doing some <a title="Video Blog Jesse Warden" href="http://www.viddler.com/explore/JesterXL/videos/" target="_blank">video capsules</a>, so you should go watch those. I used to make the new guys watch them when they had nothing to do (when is the next one coming out Mr Warden? I want more!). Aside from this Jesse, it was also good to see that <a title="Jesse Freeman" href="http://www.jessefreeman.com/" target="_blank">Jesse Freeman</a> is a very well spoken, nice , intelligent and professional dude. It clashes from his Twitter personality where all he does is wine about Adobe (well he seems to like Adobe now that he is working with Flash on Android). I really enjoy his <a title="Jesse Freeman's articles on InsideRIA" href="http://www.insideria.com/jesse-freeman/" target="_blank">articles on InsideRIA</a> but sometimes I want to unfollow him on Twitter because all his bitchin is impacting on my moral. It was nice to see him in person, it gives me a new (good) perspective on the guy. Also another interesting thing I learned was that searching for Flash Bum (Jesse&#8217;s username on Twitter is theflashbum) on Google images yields unexpected results.</p>
<p>All in all it was a great week-end, I wish good luck to the Flash and the City team for next year.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Frealisation-from-flash-and-the-city%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/realisation-from-flash-and-the-city/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Dependency Injection; Ok but how?</title>
		<link>http://www.zedia.net/2010/dependency-injection-ok-but-how/</link>
		<comments>http://www.zedia.net/2010/dependency-injection-ok-but-how/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 17:56:58 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[compiler arguments]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[describeType]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[Fabien Potentier]]></category>
		<category><![CDATA[Jeff More]]></category>
		<category><![CDATA[Joel Hooks]]></category>
		<category><![CDATA[SwiftSuspenders]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=575</guid>
		<description><![CDATA[More Robotlegs for you guys, but this time in is more conceptual. One thing that bugged me with Robotlegs was the use of the expression Dependency Injection. Cool word, it must mean something huge. Well if you look at it quickly; not really. If you take time to think about it, it means more. Half [...]]]></description>
			<content:encoded><![CDATA[<p>More Robotlegs for you guys, but this time in is more conceptual.</p>
<p>One thing that bugged me with <a title="Robotlegs" href="http://www.robotlegs.org" target="_blank">Robotlegs</a> was the use of the expression Dependency Injection. Cool word, it must mean something huge. Well if you look at it quickly; not really. If you take time to think about it, it means more.</p>
<h3>Half of it is injection</h3>
<p>Well, how you implement dependency injection is actually pretty simple and is something that you are doing every day (well if you program). Dependency Injection is giving, by the mean of the contructor, a method or a property, dependency (data) to an object. As <a title="Dependency Injection" href="http://www.insideria.com/2009/09/as3-dependency-injection-demys.html" target="_blank">Joel Hooks said it in his InsideRIA article</a> (read it, it&#8217;s a good intro): &#8220;<em>When you pass a variable to the constructor of a class, you are using Dependency Injection. When you set a property on a class, you are using Dependency Injection.</em>&#8221;</p>
<p>Ain&#8217;t that just pleasing; I can just walk around the office and tell every one I am doing Dependency Injection.</p>
<h3>The concept behind it</h3>
<p>I first was reading about this on the Robotlegs best practices and I couldn&#8217;t understand anything (that&#8217;s mostly the case when I am first exposed to a design pattern, no offense to that document). After that I found <a title="Dependency Injection" href="http://www.insideria.com/2009/09/as3-dependency-injection-demys.html" target="_blank">Hooks article</a> and I said to myself: &#8220;this ain&#8217;t complicated, why all the fuss&#8221;, but I wasn&#8217;t really understanding the concept (the why) behind it. It took me <a title="Dependency Injection" href="http://fabien.potencier.org/article/11/what-is-dependency-injection">this article</a> to really understand. The example is really simple and clearly expose why we should use dependency injection.</p>
<p>Why we should use dependency injection is mostly to create more flexible Classes. If a Class as settings that could change and that it depends on them to work, these settings should not be set inside the Class&#8217; code but outside of it. That way every time the settings change, you don&#8217;t need to go in the Class&#8217; code to change them.  You should really read <a title="Dependency Injection" href="http://fabien.potencier.org/article/11/what-is-dependency-injection" target="_blank">Fabien Potentier&#8217;s article</a> about it; he does a way better job at explaining this than me. Also this <a title="Dependency Injection" href="http://www.procata.com/talks/phptek-may2007-dependency.pdf" target="_blank">presentation by Jeff More</a> is pretty good. The more you read about it the more you&#8217;ll understand what it is.</p>
<h3>Fine but it still feels like magic in Robotlegs</h3>
<p>When you read the <a title="Dependency Injection" href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank">wikipedia article on Dependency Injection</a>, at one point they list some draw backs and one of them was that &#8220;<em>Code that uses dependency injection can seem magical to some developers</em>&#8221; and that is exactly how I felt about it in the context of Robotlegs. Mostly because of the use of the <strong>[Inject]</strong> metatag. That is not a mechanism I was used to in AS3. I was thinking that these meta where holy blessed keywords that only Adobe could create.</p>
<p><a href="http://www.zedia.net/wp-content/uploads/2010/03/inject.jpg"><img class="aligncenter size-full wp-image-584" title="inject" src="http://www.zedia.net/wp-content/uploads/2010/03/inject.jpg" alt="" width="474" height="151" /></a></p>
<p>Well it turns out I was wrong. Well half wrong. The <strong>[Inject]</strong> meta is used at runtime while let&#8217;s say the <strong>[Embed]</strong> metatag is used at compile time, so it is not exactly the same beast. In Robotlegs, injection is handled by the <a title="SwiftSuspenders" href="http://github.com/tschneidereit/SwiftSuspenders">SwiftSuspenders</a>. What it does is that for all rules you create using the method mapValue, mapClass and mapSingleton it will inspect the classes it receive. It uses the function <a title="describeType AS3" href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#describeType()" target="_blank">flash.utils.describeType</a> on the Class to do so, this will return an XML that represent that Class. In this XML, there will be tags that represent the <strong>[Inject]</strong> metatag. That is what SwiftSuspenders is looking for when parsing the class representation XML, after that it can freely do the injection (passing the values) according to the rules.</p>
<p>Now you could go and create your own metatags, but it seems that the compiler would remove them at compilation. If you use the source for the SwiftSuspenders instead of the SWC they tell you to add this to the compiler arguments:</p>
<p><em><strong>-keep-as3-metadata+=Inject</strong></em></p>
<p><em><strong>-keep-as3-metadata+=PostConstruct</strong></em> <span style="color: #888888;">//This is another metatag that SwiftSuspenders makes use of</span></p>
<p>This will prevent the compiler from removing the metatags from the Classes, so you could basically change these lines to make the compiler keep your newly created metatags. I have no idea why you don&#8217;t have to do this when using the SWC.</p>
<p>That is kinda what I wanted to cover. I&#8217;m still not fully comfortable with dependency injection but at least I have a better idea of how it works underneath. I hope you feel the same.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fdependency-injection-ok-but-how%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/dependency-injection-ok-but-how/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Recharge with milk and Robotlegs</title>
		<link>http://www.zedia.net/2010/recharge-with-milk-and-robotlegs/</link>
		<comments>http://www.zedia.net/2010/recharge-with-milk-and-robotlegs/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 17:50:16 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[Twist Image]]></category>
		<category><![CDATA[Recharge with Milk]]></category>
		<category><![CDATA[Robotlegs]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=579</guid>
		<description><![CDATA[I just wanted to show you what came out of my work with Robotlegs. Recharge with Milk is a hybrid site Html/Flash. We did the flash part because for the home section it would be faster to take care of the page resizing and to add some animations in the compare tool. Only the home [...]]]></description>
			<content:encoded><![CDATA[<p>I just wanted to show you what came out of my work with <a title="Robotlegs" href="http://www.robotlegs.org" target="_blank">Robotlegs</a>. <a title="Recharge with Milk" href="http://www.rechargewithmilk.ca" target="_blank">Recharge with Milk</a> is a hybrid site Html/Flash. We did the flash part because for the home section it would be faster to take care of the page resizing and to add some animations in the <a title="Recharge with milk compare tool" href="http://www.rechargewithmilk.ca/compare-it.php" target="_blank">compare tool</a>.</p>
<p>Only the home page was built using Robotlegs. It is pretty simple so it was a good fit to try a new framework, but there is way more going on than what it looks like. Everything on the home page is customizable from a xml and there are a lot of layers of views.</p>
<p><a href="http://www.rechargewithmilk.ca/"><img class="aligncenter size-full wp-image-580" title="podiumScreen" src="http://www.zedia.net/wp-content/uploads/2010/03/podiumScreen.jpg" alt="Recharge with Milk" width="644" height="408" /></a></p>
<p>At some point in the project I was finding real beauty in the code, but I was really sad because nobody other than developer could see that beauty&#8230;</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Frecharge-with-milk-and-robotlegs%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/recharge-with-milk-and-robotlegs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some tricks when switching to Robotlegs from PureMVC</title>
		<link>http://www.zedia.net/2010/some-tricks-when-switching-to-robotlegs-from-puremvc/</link>
		<comments>http://www.zedia.net/2010/some-tricks-when-switching-to-robotlegs-from-puremvc/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 19:20:41 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[PureMVC]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=569</guid>
		<description><![CDATA[From the past posts and a couple of tweets, you all know I have been playing around with Robotlegs. Also, up until now, my framework of choice has been PureMVC, so what I want to do in this post is inform you of the little road bumps I hit when trying to learn the new [...]]]></description>
			<content:encoded><![CDATA[<p>From the <a title="Robotlegs file templates" href="http://www.zedia.net/2010/robotlegs-templates-for-flashdevelop/" target="_blank">past</a> <a title="Robotlegs project templates" href="http://www.zedia.net/2010/and-now-an-as3-project-robotlegs-project-template-for-flashdevelop/" target="_self">posts</a> and a couple of tweets, you all know I have been playing around with <a title="Robotlegs" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a>. Also, up until now, my framework of choice has been <a title="PureMVC" href="http://www.puremvc.org/" target="_blank">PureMVC</a>, so what I want to do in this post is inform you of the little road bumps I hit when trying to learn the new framework.</p>
<h2>Public dependency injection</h2>
<p>The first one is really small. Robotlegs makes use of dependency injection (more on that in a later post) and to do so you have to put a meta tag [Inject] before you variable declaration. That is all good, just remember to make your variable public or else you&#8217;ll get an error. I wasn&#8217;t accustomed with the error I got so it took me some time to find out why I got it.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>Inject<span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> view:Footer; <span style="color: #808080; font-style: italic;">//remember to make public injectable variables</span></pre></div></div>

<h2>Playing with models</h2>
<p>First thing first, when creating my model I was looking to extend the Model class from the Robotlegs framework. Turns out there is no such class; models should extend the Actor class. Services also extends the Actor class.</p>
<p>The next gotcha was a little weird to me at first because it is different from PureMVC mindset. Robotlegs does lazy instantiation, so when you map a model using the injector.mapSingleton method the model will only be created the first time it is injected (that is how I understood it). For some models this is ok, but for others they need to be created before that. In order to do so you use injector.instantiate method and pass it the class you want to create. Here is the code for it and how you would pass data to your newly created model:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">injector.<span style="color: #006600;">mapSingleton</span><span style="color: #66cc66;">&#40;</span>ApplicationModel<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> appModel:ApplicationModel = injector.<span style="color: #006600;">instantiate</span><span style="color: #66cc66;">&#40;</span>ApplicationModel<span style="color: #66cc66;">&#41;</span>;
appModel.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;whatever you want here&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h2>Where do I list and handle framework events?</h2>
<p>This is the big plus for Robotlegs, no more handling notifications but not listing them and then not figuring out why it doesn&#8217;t work. Robotlegs uses the same mechanism, in a mediator, to listen to view events than to listen to framework events which makes it easier to deal with.</p>
<p>So to listen to a view event I would do this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">eventMap.<span style="color: #006600;">mapListener</span><span style="color: #66cc66;">&#40;</span>view, StringEvent.<span style="color: #006600;">HIT_ZONE_ROLL_OUT</span>, _onRollOut, StringEvent<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>and to listen to a framework event I would do this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">eventMap.<span style="color: #006600;">mapListener</span><span style="color: #66cc66;">&#40;</span>eventDispatcher, StringEvent.<span style="color: #006600;">RESIZE</span>, _onResize, Event<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Robotlegs basically wraps around the traditional addEventListener method and what does this give us as an additional bonus? We don&#8217;t ever have to set these listeners to weak reference because that is the way they are set by default. Oh, the joy!</p>
<p>Learning a new framework isn&#8217;t an easy task (at least when you don&#8217;t know any), but I found that learning Robotlegs from a PureMVC background was pretty easy. I hope you will take the time to check it out.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fsome-tricks-when-switching-to-robotlegs-from-puremvc%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/some-tricks-when-switching-to-robotlegs-from-puremvc/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>And now an AS3 Project &#8211; Robotlegs project template for FlashDevelop</title>
		<link>http://www.zedia.net/2010/and-now-an-as3-project-robotlegs-project-template-for-flashdevelop/</link>
		<comments>http://www.zedia.net/2010/and-now-an-as3-project-robotlegs-project-template-for-flashdevelop/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 18:04:14 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=561</guid>
		<description><![CDATA[So yesterday I gave you files templates for Robotlegs. I now give you a project template. File templates are used when you want to add a new file to a project, project templates are used at the creation of a project. It will create the folder structure, add libraries and create the basic files you will need [...]]]></description>
			<content:encoded><![CDATA[<p>So yesterday I gave you <a title="Robotlegs files templates for FlashDevelop" href="http://www.zedia.net/2010/robotlegs-templates-for-flashdevelop/" target="_self">files templates for Robotlegs</a>. I now give you a project template. File templates are used when you want to add a new file to a project, project templates are used at the creation of a project. It will create the folder structure, add libraries and create the basic files you will need in most projects of that type.</p>
<p>In this <a title="Robotlegs framewrok" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> project template I added 7 files : Preload.fla, Main.as, IMain.as, MainContext.as, CreateModelsCommand.as, CreateMediatorsCommand.as and ApplicationModel.as.</p>
<p>I added the Preload.fla because <a href="http://www.zedia.net/2010/more-on-preloaders-passing-the-loaderinfo/" targe="_self">has explained in this post</a>, I pass the loaderInfo(I do this to pass the flashvars) from the preloader to the loaded Main so I thought it would make understanding why I did that in the Main easier. This is a template preloader so there is no graphics in it, just the basic code to make a preloader work.</p>
<p>In the Main.as I also do some weird things, namely this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Capabilities</span>.<span style="color: #0066CC;">playerType</span> == <span style="color: #ff0000;">&quot;StandAlone&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = StageScaleMode.<span style="color: #006600;">NO_SCALE</span>;
<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span> = StageAlign.<span style="color: #006600;">TOP_LEFT</span>;
init<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">loaderInfo</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//and this in the init method</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Capabilities</span>.<span style="color: #0066CC;">playerType</span> == <span style="color: #ff0000;">&quot;StandAlone&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
local = <span style="color: #000000; font-weight: bold;">true</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>I do this to test locally without having to compile the preloader every time. Also, I might need to know if I am local if I use AMF. In that case, the url for my gateway will be different.</p>
<p>For the rest, it is pretty straight forward, a MainContext for the application that will start it, a command to create the models, a command to create the mediators and finally an ApplicationModel. I don&#8217;t create the ApplicationModel in the CreateModelsCommand because I want to parse the data(parameters) inside of the LoaderInfo I passed in the constructor of the MainContext.</p>
<p>If you use this project template along with the <a title="Robotlegs file templates" href="http://www.zedia.net/files/RobotlegsTemplates.rar" target="_self">files templates</a>, you&#8217;re in for major time saving while enjoying Robotlegs!</p>
<p>Here are the files:<br />
<a title="Robotlegs Project template files" href="http://www.zedia.net/files/000 ActionScript 3 - AS3 Project with Robotlegs.rar" target="_self">000 ActionScript 3 &#8211; AS3 Project with Robotlegs.rar</a></p>
<p>So when you downloaded the files, go in <a title="FlashDevelop" href="http://www.flashdevelop.org/wikidocs/index.php?title=Main_Page" target="_blank">FlashDevelop</a>, in the top menu select Tools and then Application Files&#8230; This will open the application files folder of FlashDevelop. Now go in the Projects Folder and add the files that you downloaded (copy the &#8220;000 ActionScript 3 &#8211; AS3 Project with Robotlegs&#8221; folder there). Now the next time you create a new project in FlashDevelop, scroll down and you will see it.</p>
<p><a href="http://www.zedia.net/wp-content/uploads/2010/02/Robotlegs22.jpg"><img class="aligncenter size-full wp-image-562" title="Robotlegs Project template" src="http://www.zedia.net/wp-content/uploads/2010/02/Robotlegs22.jpg" alt="" width="543" height="476" /></a></p>
<p>You may not agree with everything that is in those templates, then there is two things you can do. Either discuss about it in the comments or modify my project template. It is very easy to do so; I never even looked at documentation to learn how to do it.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fand-now-an-as3-project-robotlegs-project-template-for-flashdevelop%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/and-now-an-as3-project-robotlegs-project-template-for-flashdevelop/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Robotlegs templates for FlashDevelop</title>
		<link>http://www.zedia.net/2010/robotlegs-templates-for-flashdevelop/</link>
		<comments>http://www.zedia.net/2010/robotlegs-templates-for-flashdevelop/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 18:26:53 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[Actor]]></category>
		<category><![CDATA[As3Signals]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[Context]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[Mediator]]></category>
		<category><![CDATA[PureMVC]]></category>
		<category><![CDATA[ResizeModel]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=556</guid>
		<description><![CDATA[I just finished my first project using Robotlegs and I can say I really like it. Way less code to write. The only thing that bothers me is that you have to create new Events when you want to pass around complex data but I think AS3Signals might fix that so I will look into [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished my first project using <a title="Robotlegs" href="http://www.robotlegs.org/" target="_blank">Robotlegs</a> and I can say I really like it. Way less code to write. The only thing that bothers me is that you have to create new Events when you want to pass around complex data but I think <a title="As3 signals" href="http://github.com/robertpenner/as3-signals" target="_blank">AS3Signals</a> might fix that so I will look into that later on.</p>
<p>Since I have all my templates for <a title="PureMVC" href="http://puremvc.org" target="_blank">PureMVC</a> done in <a title="FlashDevelop" href="http://www.flashdevelop.org/" target="_blank">FlashDevelop</a>, I thought I would do the same for Robotlegs. So I have built a template for a Command, a Context, a Mediator, an Actor and I also put in a ResizeModel (I know some people do this in a mediator but if you want to change this go ahead). Now, I don&#8217;t think these will be perfect, but it is a good starting point.</p>
<p>I am also working on a AS3 Project &#8211; Robotlegs template, but I want to try it out before I give it out. When I am pleased with it, I&#8217;ll post it along with an update of the other templates.</p>
<p>Here is the files with the templates:</p>
<p><a href="http://www.zedia.net/files/RobotlegsTemplates.rar" target="_self">RobotlegsTemplates.rar</a></p>
<p>To add them in FlashDevelop, in the Tools menu click in Application Files. This will open the folder where the applications files for FlashDevelop are. In there open the Templates folder, then the ProjectFiles folder, then the AS3Project folder. Now copy the Robotlegs folder you downloaded there. To use them, in the project view in FlashDevelop, right click on a folder, click &#8220;Add&#8221; and then Robotlegs. At that point you will see the five templates you just added.</p>
<p><a href="http://www.zedia.net/wp-content/uploads/2010/02/RobotlegsTemplates.jpg"><img class="aligncenter size-full wp-image-557" title="Robotlegs Templates for Flash Develop" src="http://www.zedia.net/wp-content/uploads/2010/02/RobotlegsTemplates.jpg" alt="Robotlegs Templates for Flash Develop" width="612" height="696" /></a></p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Frobotlegs-templates-for-flashdevelop%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/robotlegs-templates-for-flashdevelop/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
