<?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; bezier</title>
	<atom:link href="http://www.zedia.net/tag/bezier/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zedia.net</link>
	<description>Flash, ActionScript, SEO and everything in between</description>
	<lastBuildDate>Thu, 02 Feb 2012 17:58:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.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>
 <p><a href="http://www.zedia.net/?flattrss_redirect&amp;id=651&amp;md5=e4c212257b10e70d184ed4ec1409e960" title="Flattr" target="_blank"><img src="http://www.zedia.net/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/drawing-bezier-tool-using-robotlegs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

