<?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; ActionScript 3</title>
	<atom:link href="http://www.zedia.net/category/actionscript-3/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>VideoMaterial with Away3D (version 3.6)</title>
		<link>http://www.zedia.net/2011/videomaterial-with-away3d-version-3-6/</link>
		<comments>http://www.zedia.net/2011/videomaterial-with-away3d-version-3-6/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 14:33:47 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Away3D]]></category>
		<category><![CDATA[panoramics]]></category>
		<category><![CDATA[sphere]]></category>
		<category><![CDATA[VideoMaterial]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=821</guid>
		<description><![CDATA[I was trying to map a video to a sphere today, so I wanted to use the VideoMaterial in Away3D, but I wasn&#8217;t finding any example on it. Also seems like it is not that straight forward so let me put an example here. Here is the base code for it (I guess SphereView could [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to map a video to a sphere today, so I wanted to use the VideoMaterial in Away3D, but I wasn&#8217;t finding any example on it. Also seems like it is not that straight forward so let me put an example here.</p>
<p>Here is the base code for it (I guess SphereView could be compiled):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SphereView<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  scene = <span style="color: #000000; font-weight: bold;">new</span> Scene3D<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #0066CC;">camera</span> = <span style="color: #000000; font-weight: bold;">new</span> Camera3D<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #0066CC;">camera</span>.<span style="color: #006600;">fov</span> = <span style="color: #cc66cc;">35</span>;
  <span style="color: #0066CC;">camera</span>.<span style="color: #006600;">z</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
  view = <span style="color: #000000; font-weight: bold;">new</span> View3D<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  view.<span style="color: #006600;">scene</span>= scene;
  view.<span style="color: #0066CC;">camera</span> = <span style="color: #0066CC;">camera</span>;
  addChild<span style="color: #66cc66;">&#40;</span>view<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  material2 = <span style="color: #000000; font-weight: bold;">new</span> VideoMaterial<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>lockW:<span style="color: #cc66cc;">2000</span>, lockH:<span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
  material2.<span style="color: #006600;">loop</span> = <span style="color: #000000; font-weight: bold;">true</span>;
  material2.<span style="color: #006600;">file</span> = <span style="color: #ff0000;">&quot;../flv/test2.flv&quot;</span>;
  material2.<span style="color: #006600;">smooth</span> = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
  sphere = <span style="color: #000000; font-weight: bold;">new</span> Sphere<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  sphere.<span style="color: #006600;">material</span> = material2;
  sphere.<span style="color: #006600;">radius</span> = <span style="color: #cc66cc;">2000</span>;
  sphere.<span style="color: #006600;">segmentsW</span> = <span style="color: #cc66cc;">40</span>;
  sphere.<span style="color: #006600;">segmentsH</span> = <span style="color: #cc66cc;">20</span>;
  sphere.<span style="color: #006600;">invertFaces</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  spherecontainer = <span style="color: #000000; font-weight: bold;">new</span> ObjectContainer3D<span style="color: #66cc66;">&#40;</span>sphere<span style="color: #66cc66;">&#41;</span>;
  scene.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>spherecontainer<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, _onEnterFrame<span style="color: #66cc66;">&#41;</span>;
  addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, _onAddedToStage<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>I had to fiddle a bit with the Away3D VideoMaterial.as to make it accept my very wide video. Find the function playStream and replace it with this one:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> playStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  _netStream = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetStream</span><span style="color: #66cc66;">&#40;</span>nc<span style="color: #66cc66;">&#41;</span>;
  _netStream.<span style="color: #006600;">checkPolicyFile</span> = <span style="color: #000000; font-weight: bold;">true</span>;
  _netStream.<span style="color: #006600;">client</span> = CustomClient;
  _netStream.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>NetStatusEvent.<span style="color: #006600;">NET_STATUS</span>, netStatusHandler,<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>;
  _netStream.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>AsyncErrorEvent.<span style="color: #006600;">ASYNC_ERROR</span>, ayncErrorHandler,<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>;
  _netStream.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>IOErrorEvent.<span style="color: #006600;">IO_ERROR</span>,ioErrorHandler,<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: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">video</span> == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// Setup video object</span>
    <span style="color: #0066CC;">video</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Video</span><span style="color: #66cc66;">&#40;</span>_lockH, _lockW<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0066CC;">video</span>.<span style="color: #0066CC;">smoothing</span> = <span style="color: #000000; font-weight: bold;">true</span>;
    sprite.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">video</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #0066CC;">video</span>.<span style="color: #006600;">attachNetStream</span><span style="color: #66cc66;">&#40;</span>_netStream<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>All I needed to do was add _lockW and _lockH to the Video constructor, but it improved the quality of the played video (it was 320&#215;240 before, the default value of Video). Now with this you should be able to start mapping your own videos inside of a sphere. Oh yeah if you want it, here are the functions that are missing in the first snippets, they basically enable you to move the camera around.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onAddedToStage<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>
  view.<span style="color: #006600;">x</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;
  view.<span style="color: #006600;">y</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>;
&nbsp;
  <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, <span style="color: #0066CC;">onMouseDown</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, <span style="color: #0066CC;">onMouseUp</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> _onEnterFrame<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>move<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    spherecontainer.<span style="color: #006600;">rotationX</span> = <span style="color: #66cc66;">&#40;</span>mouseY - lastMouseY<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">10</span> + lastRotationX;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>spherecontainer.<span style="color: #006600;">rotationX</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #66cc66;">&#41;</span>
      spherecontainer.<span style="color: #006600;">rotationX</span> = <span style="color: #cc66cc;">90</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>spherecontainer.<span style="color: #006600;">rotationX</span> <span style="color: #66cc66;">&lt;</span> -<span style="color: #cc66cc;">90</span><span style="color: #66cc66;">&#41;</span>
      spherecontainer.<span style="color: #006600;">rotationX</span> = -<span style="color: #cc66cc;">90</span>;
    sphere.<span style="color: #006600;">rotationY</span> = <span style="color: #66cc66;">&#40;</span>lastMouseX - mouseX<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">10</span> + lastRotationY;
  <span style="color: #66cc66;">&#125;</span>			
  view.<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</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> <span style="color: #0066CC;">onMouseDown</span><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>
  lastRotationX = spherecontainer.<span style="color: #006600;">rotationX</span>;
  lastRotationY = sphere.<span style="color: #006600;">rotationY</span>;
  lastMouseX = mouseX;
  lastMouseY = mouseY;
  move = <span style="color: #000000; font-weight: bold;">true</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onMouseUp</span><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>
  move = <span style="color: #000000; font-weight: bold;">false</span>;  
<span style="color: #66cc66;">&#125;</span></pre></div></div>

 <p><a href="http://www.zedia.net/?flattrss_redirect&amp;id=821&amp;md5=5d49b9bd44f02f0684cb07aac222370b" 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/2011/videomaterial-with-away3d-version-3-6/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TLFTextfield blocking &#8220;ENTER&#8221; Keyboard event</title>
		<link>http://www.zedia.net/2011/tlftextfield-blocking-enter-keyboard-event/</link>
		<comments>http://www.zedia.net/2011/tlftextfield-blocking-enter-keyboard-event/#comments</comments>
		<pubDate>Tue, 24 May 2011 14:42:20 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[TLFTextField]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=815</guid>
		<description><![CDATA[Probably my last post about TLFTextfied for a little while. This is going to be a quick one and was actually found by my colleague Will Adams. Also he found the solution somewhere else on the web but I can&#8217;t find it anymore so I thought it would be good to post it here too. [...]]]></description>
			<content:encoded><![CDATA[<p>Probably my last post about TLFTextfied for a little while. This is going to be a quick one and was actually found by my colleague <a title="Will Adams" href="http://extralush.com/">Will Adams</a>. Also he found the solution somewhere else on the web but I can&#8217;t find it anymore so I thought it would be good to post it here too.</p>
<p>So here is the problem, if you use TLFTexfields as input fields for your form and you want to listen for the user pressing the &#8220;ENTER&#8221; key to submit the form, if at that moment the focus is on the input field, you won&#8217;t be able to listen for it. So normally, you would put the Keyboard event listener on the stage so that it doesn&#8217;t matter which textfield the user is on, if he presses &#8220;ENTER&#8221;, it will submit the form. Turns out that for some reasons, TLFTextfield will block that event from firing. Funny thing, is that it doesn&#8217;t block other key press events from firing just the &#8220;ENTER&#8221; (or &#8220;RETURN&#8221;).</p>
<p>Now for the quick fix:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">_tlfTextfield.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_UP</span>, _onKeyPressed<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>So you will have to add this to every of your textfields, which is a bit annoying, but it will make it work. I don&#8217;t know how the guy that found this found it, but I&#8217;m sure glad he did.</p>
 <p><a href="http://www.zedia.net/?flattrss_redirect&amp;id=815&amp;md5=ee7aa9c8a12b70a5449aefdc90556d99" 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/2011/tlftextfield-blocking-enter-keyboard-event/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Difference between TextField and TextBloc (or TextLine)</title>
		<link>http://www.zedia.net/2011/difference-between-textfield-and-textbloc-or-textline/</link>
		<comments>http://www.zedia.net/2011/difference-between-textfield-and-textbloc-or-textline/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 15:03:40 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[text engine]]></category>
		<category><![CDATA[TextBloc]]></category>
		<category><![CDATA[TextElement]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[TextFormat]]></category>
		<category><![CDATA[TextLine]]></category>
		<category><![CDATA[TLF Framework]]></category>
		<category><![CDATA[TLFTextField]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=797</guid>
		<description><![CDATA[Ok I have been writing a lot about TLF Framework lately and it is definitely not my favorite topic but I thought people should be aware of this. So here you go : using the new text engine will actually give you better looking text! When I say text engine, I mean using TextBloc and [...]]]></description>
			<content:encoded><![CDATA[<p>Ok I have been writing a lot about TLF Framework lately and it is definitely not my favorite topic but I thought people should be aware of this. So here you go : using the new text engine will actually give you better looking text! When I say text engine, I mean using TextBloc and TextLine. Here is a little example I made to show the difference. On the left it is a good old TextField, in the middle we have the new TLFTextField and on the right I am using TextBloc / TextLine (TextBloc for now on).</p>
<p>
<object width="640" height="140">
<param name="movie" value="http://www.zedia.net/wp-content/uploads/2011/04/MainTLF.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<embed type="application/x-shockwave-flash" width="640" height="140" src="http://www.zedia.net/wp-content/uploads/2011/04/MainTLF.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>As you can see there is nearly no difference between using a TextField and a TLFTextField, the actual code is also the same, the difference is that you need to use a DF4 exported font (some new none-sense setting in Flash CS5). On the other hand, when using TextBloc, it does look better, I agree it is subtle, but it is better. I am writing this post because I was arguing with a colleague that there was no difference, but he showed it to me, I hope this does the same to you.<br />
&nbsp;</p>
<h3>Using TextBloc</h3>
<p>Now when using TextBloc, a lot changed from using the good old TextField. First, you need to use the class ElementFormat instead of TextFormat. Here is an example on how to do so:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">font</span>:AvantGardeGothicStdBook = <span style="color: #000000; font-weight: bold;">new</span> AvantGardeGothicStdBook<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//this is a font embedded in a swc</span>
<span style="color: #000000; font-weight: bold;">var</span> fontDesc:FontDescription = <span style="color: #000000; font-weight: bold;">new</span> FontDescription<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">font</span>.<span style="color: #006600;">fontName</span><span style="color: #66cc66;">&#41;</span>;
fontDesc.<span style="color: #006600;">fontLookup</span> = FontLookup.<span style="color: #006600;">EMBEDDED_CFF</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> style:ElementFormat = <span style="color: #000000; font-weight: bold;">new</span> ElementFormat<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
style.<span style="color: #006600;">fontDescription</span> = fontDesc;
style.<span style="color: #006600;">fontSize</span> = <span style="color: #cc66cc;">32</span>;
style.<span style="color: #0066CC;">color</span> = 0xf9827f;</pre></div></div>

<p>&nbsp;</p>
<p>When you want to display a single line of text, it is fairly easy to do so. Here is how to do it:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> element:TextElement = <span style="color: #000000; font-weight: bold;">new</span> TextElement<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;TEXTLINE!!!!&quot;</span>, style<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// we defined style earlier</span>
<span style="color: #000000; font-weight: bold;">var</span> textBlock:TextBlock = <span style="color: #000000; font-weight: bold;">new</span> TextBlock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;			
textBlock.<span style="color: #006600;">content</span> = element;
<span style="color: #000000; font-weight: bold;">var</span> textline:TextLine = textBlock.<span style="color: #006600;">createTextLine</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span>;
textline.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">430</span>;
textline.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">36</span>;
addChild<span style="color: #66cc66;">&#40;</span>textline<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>&nbsp;</p>
<p>The things get more complicated when you want to display a paragraph:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> elementPar:TextElement = <span style="color: #000000; font-weight: bold;">new</span> TextElement<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;This is what some normal text in a textline paragraph looks like. The difference is subtle but there is one with the textline stuff.&quot;</span>, stylePar<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> textBlockPar:TextBlock = <span style="color: #000000; font-weight: bold;">new</span> TextBlock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
textBlockPar.<span style="color: #006600;">content</span> = elementPar;
<span style="color: #000000; font-weight: bold;">var</span> paragraph:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> line:TextLine = textBlockPar.<span style="color: #006600;">createTextLine</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> currentY:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>line<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	line.<span style="color: #006600;">y</span> = currentY;
	currentY += line.<span style="color: #0066CC;">height</span>;
	paragraph.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>line<span style="color: #66cc66;">&#41;</span>;
	line = textBlockPar.<span style="color: #006600;">createTextLine</span> <span style="color: #66cc66;">&#40;</span>line, <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
paragraph.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">430</span>;
paragraph.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">63</span>;
addChild<span style="color: #66cc66;">&#40;</span>paragraph<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>&nbsp;</p>
<p>So what now? Should we all start using TextBloc? I don&#8217;t know and to be frank it seems like even <a title="TextField future in Flash" href="http://www.bytearray.org/?p=2767" target="_blank">Adobe doesn&#8217;t know</a>. But if you want better looking text, maybe you should.</p>
 <p><a href="http://www.zedia.net/?flattrss_redirect&amp;id=797&amp;md5=2c8e663e7d6e97c571cdd9721b02fd48" 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/2011/difference-between-textfield-and-textbloc-or-textline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Donut Charts in AS3</title>
		<link>http://www.zedia.net/2011/donut-charts-in-as3/</link>
		<comments>http://www.zedia.net/2011/donut-charts-in-as3/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 14:24:20 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Charts]]></category>
		<category><![CDATA[Donut Chart]]></category>
		<category><![CDATA[Lee Brimeloww]]></category>
		<category><![CDATA[Pie Charts]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=787</guid>
		<description><![CDATA[Most of what I write comes from goals that I must achieve through my work and when I search the web to figure out how to do those I find very little information. So usually once I have figured it out I write a post about it. I was looking to create some donut charts [...]]]></description>
			<content:encoded><![CDATA[<p>Most of what I write comes from goals that I must achieve through my work and when I search the web to figure out how to do those I find very little information. So usually once I have figured it out I write a post about it. I was looking to create some donut charts which are basically pie charts but with a mask on them to make a hole in the middle. All I could find on the web was solutions that you had to pay for, bundles of charts that looked really bad. So I thought it shouldn&#8217;t be that bad to just to them from scratch.</p>
<p>Well I actually didn&#8217;t do them from scratch, first I translated some <a title="Drawing API" href="http://flash-creations.com/notes/dynamic_drawingapi.php">old ActionScript 2 found here</a> to make the donut mask and I used <a title="Lee Brimelow wedge class" href="http://blog.theflashblog.com/?p=430">Lee Brimelow wedge class</a> to create the subdivision of the chart. So here are four examples of what you can do with it:</p>
<p>&nbsp;</p>
<p>
<object width="480" height="120">
<param name="movie" value="http://www.zedia.net/wp-content/uploads/2011/04/DonutMain.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<param name="allowScriptAccess" value="always"></param>
<embed type="application/x-shockwave-flash" width="480" height="120" src="http://www.zedia.net/wp-content/uploads/2011/04/DonutMain.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>&nbsp;</p>
<p>And here is the code used to create them:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> wedgeVector:Vector.<span style="color: #66cc66;">&lt;</span>ChartWedgeInfo<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>ChartWedgeInfo<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
wedgeVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ChartWedgeInfo<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.3</span>, 0x70ddff<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
wedgeVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ChartWedgeInfo<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.21</span>, 0x56baec<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
wedgeVector.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ChartWedgeInfo<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.3</span>, 0x2b78d2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
_donut1 = <span style="color: #000000; font-weight: bold;">new</span> DonutChart<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">20</span>, 0x1e457a, wedgeVector<span style="color: #66cc66;">&#41;</span>;
_donut1.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">60</span>;
_donut1.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">60</span>;
addChild<span style="color: #66cc66;">&#40;</span>_donut1<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> wedgeVector2:Vector.<span style="color: #66cc66;">&lt;</span>ChartWedgeInfo<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>ChartWedgeInfo<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
wedgeVector2.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ChartWedgeInfo<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.5</span>, 0xfca25a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
_donut2 = <span style="color: #000000; font-weight: bold;">new</span> DonutChart<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">10</span>, 0x821626, wedgeVector2<span style="color: #66cc66;">&#41;</span>;
_donut2.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">180</span>;
_donut2.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">60</span>;
addChild<span style="color: #66cc66;">&#40;</span>_donut2<span style="color: #66cc66;">&#41;</span>;
&nbsp;
_donut3 = <span style="color: #000000; font-weight: bold;">new</span> DonutChart<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span>, <span style="color: #cc66cc;">25</span>, 0x56baec<span style="color: #66cc66;">&#41;</span>;
_donut3.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">300</span>;
_donut3.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">60</span>;
addChild<span style="color: #66cc66;">&#40;</span>_donut3<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> wedgeVector3:Vector.<span style="color: #66cc66;">&lt;</span>ChartWedgeInfo<span style="color: #66cc66;">&gt;</span> = <span style="color: #000000; font-weight: bold;">new</span> Vector.<span style="color: #66cc66;">&lt;</span>ChartWedgeInfo<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
wedgeVector3.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ChartWedgeInfo<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.3</span>, 0xfca25a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
wedgeVector3.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ChartWedgeInfo<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.3</span>, 0xfd8332<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
wedgeVector3.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ChartWedgeInfo<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.3</span>, 0xde4649<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
wedgeVector3.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ChartWedgeInfo<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.3</span>, 0xaa2c34<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
wedgeVector3.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ChartWedgeInfo<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.3</span>, 0x821626<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
_donut4 = <span style="color: #000000; font-weight: bold;">new</span> DonutChart<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">30</span>, 0x821626, wedgeVector3<span style="color: #66cc66;">&#41;</span>;
_donut4.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">420</span>;
_donut4.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">60</span>;
addChild<span style="color: #66cc66;">&#40;</span>_donut4<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>I think it is pretty easy to use. Here are some considerations; if you don&#8217;t give in any wedge info, it will just draw a donut, you can give more than 100% for your chart it will just loop, and the chart 0,0 is at the center of the donut. So here you go, you can just download the files below. I think it could be improved a little and there is no options to put labels or anything but it should fit more use cases that way.</p>
<p><a href="http://www.zedia.net/wp-content/uploads/2011/04/DonutChartsSource.zip">DonutChartsSource</a></p>
 <p><a href="http://www.zedia.net/?flattrss_redirect&amp;id=787&amp;md5=28b70198f848310a5e4be2fb9b2c3b30" 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/2011/donut-charts-in-as3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>RTL languages and the Text Layout Framework</title>
		<link>http://www.zedia.net/2011/rtl-languages-and-the-text-layout-framework/</link>
		<comments>http://www.zedia.net/2011/rtl-languages-and-the-text-layout-framework/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 20:47:54 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Arabic]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Hebrew]]></category>
		<category><![CDATA[Persian]]></category>
		<category><![CDATA[Right to left languages]]></category>
		<category><![CDATA[RTL]]></category>
		<category><![CDATA[Text Layout Framework]]></category>
		<category><![CDATA[TextBlock]]></category>
		<category><![CDATA[TextFlow]]></category>
		<category><![CDATA[TLFTextField]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=781</guid>
		<description><![CDATA[So this is the positive post about the Text Layout Framework that I was talking about earlier. For the current project I am working on I have the joy (read the sarcasm here) to be doing it in 9 languages and if that wasn&#8217;t fun enough one of those is Hebrew which is a right [...]]]></description>
			<content:encoded><![CDATA[<p>So this is the positive post about the Text Layout Framework that I was <a title="New Text Layout Framework, same font problems" href="http://www.zedia.net/2011/new-text-layout-framework-same-font-problems/">talking about earlier</a>. For the current project I am working on I have the joy (read the sarcasm here) to be doing it in 9 languages and if that wasn&#8217;t fun enough one of those is Hebrew which is a right to left language. To be frank this kinda make the project really hard but not because of technical reasons, it makes it hard just to put the text at the right place&#8230; Anyway I digress, the thing when working with right to left languages is that there is not that much information on it or what you will find is really dated and not relevant anymore. Well it is that way with TLF in general too, so finding information on the subject is really tedious. Actually I didn&#8217;t find anything useful on the web and I had to figure things out on my own; that is why I am writing this post. Has I mentioned on the previous post, there are 3 ways to make text using the TLF: TLFTextfield, TextBlock or TextFlow. I will go through all of those and explain how to display RTL language correctly.</p>
<h3>TLFTextfield</h3>
<p>I find that this is the easiest way to display text using the Text Layout Framework. It is easy because it pretty much works the same as the good old Textfield. A colleague told me that the CSS part of it wasn&#8217;t really working and from the <a title="TLFTextfield" href="http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/fl/text/TLFTextField.html">documentation</a> it seems to be still in beta. To display a right to left language like Arabic, Hebrew or Persian, this seems like the way to go. Easily enough, it has a property called direction that you can just set to &#8220;rtl&#8221; and there you go, your text will display properly.</p>
<h3>TextBlock</h3>
<p>If you think you are going to be doing a version of your site/application for a RTL language, do not use TextBlock. That&#8217;s a shame cause this method of displaying text seems to give better looking text, but I was never able to get my Hebrew text displaying properly. It is weird because if you look at the <a title="BidiLevel on TextBlock" href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/engine/TextBlock.html#bidiLevel">documentation</a> there seems to be a way to do it, using the bidiLevel property and setting it to an odd number (I have no idea why, this seems very unobvious to me). But I tried it and it doesn&#8217;t work. The problem arise when you have LTR text inside a RTL paragraph, so let&#8217;s say a english word inside a Arabic paragraph. This will greatly confuse the text engine and your text won&#8217;t display properly sometimes showing very differently than it the xml it has been taken from (if you pull your text from xml). So in this case, use TLFTextfield.</p>
<h3>TextFlow</h3>
<p>I am not a big fan of TextFlow, it seems more complicated for nothing, but I guess that if you want to display columns and more complex text that is the way to go. But has in the case of the TLFTextfield, it seems pretty easy to use RTL languages and TextFlow. So basically in your TextFlow markup you can do something like that &lt;flow:p direction=&#8221;rtl&#8221;&gt;my persian content&lt;/flow:p&gt;. Easy enough, I haven&#8217;t tried it, but I have read that it works.</p>
<p>So there you have it, how I finally got it to work properly. Had I known before I would have built my site differently, I was using TextBlock everywhere, so now I check if the language is Hebrew and use TLFTextfield in that case. Also note that working with right to left text using tools that don&#8217;t really support it is really hard and confusing, the editor gets confused and selecting text becomes hell as it goes a bit for right then to the left and then right again. Be prepared for some trouble&#8230; Anyway I hope this saved some a bit.</p>
 <p><a href="http://www.zedia.net/?flattrss_redirect&amp;id=781&amp;md5=28e83f478d682cfb70b51dc62cb2f032" 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/2011/rtl-languages-and-the-text-layout-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Text Layout Framework, same font problems</title>
		<link>http://www.zedia.net/2011/new-text-layout-framework-same-font-problems/</link>
		<comments>http://www.zedia.net/2011/new-text-layout-framework-same-font-problems/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 15:39:02 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[DF3]]></category>
		<category><![CDATA[DF4]]></category>
		<category><![CDATA[Embed]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[Text Layout Framework]]></category>
		<category><![CDATA[TextBlock]]></category>
		<category><![CDATA[TextFlow]]></category>
		<category><![CDATA[TextLine]]></category>
		<category><![CDATA[TLF]]></category>
		<category><![CDATA[TLFTextField]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=775</guid>
		<description><![CDATA[I guess this has been said before, but I really feel like ranting. I will post a positive article later on about TLF, but for now I need to vent. So I guess the problem come from the fact that I thought the new Text Layout Framework would solve all problems relating to fonts and [...]]]></description>
			<content:encoded><![CDATA[<p>I guess this has been said before, but I really feel like ranting. I will post a positive article later on about TLF, but for now I need to vent.</p>
<p>So I guess the problem come from the fact that I thought the new Text Layout Framework would solve all problems relating to fonts and Flash. But I guess that was hoping for too much. TLF does have a good side, it does make your text look better. I was skeptic at first, but it really does. The problem is, it has a lot of bad sides.</p>
<p>First problem is that it will add between 100k to 160k to your file size (pretty much forget about it for banners) and that is for every SWF that uses it. I don&#8217;t know about you but the sites I build usually contain at least 4 SWFs, so that&#8217;s nearly a megabyte just for the text engine, you&#8217;re not embedding the fonts yet or adding any content. There are ways to circumvent that but you still have to figure it out and it involves another workflow.</p>
<p>Secondly, there is not much documentation about it. I have been looking and it is pretty hard to figure out what is working or not. Seems like TLF changed since it was introduced, so some information is not relevant anymore. The other thing is that there are multiple ways to use it, you can use TextBlock and TextLine, you can use TLFTextField or you can use TextFlow. It gets pretty confusing at some point, cause you don&#8217;t solve the same problems the same ways with each of the three option I named before.</p>
<p>Lastly, it doesn&#8217;t work in every situation, I gave the banner example previously, but using the Text Layout Framework is also very expensive CPU wise. For example I was making this combobox which had an opened state with about a hundred items in it. Well it made the site become very slow. I was using TextLines and I had to revert to using good old TextFields. Which introduced a new problem, the font format that you use for TLF is not compatible with the old TextFields, so in this case I had to embed the same font twice, once DF3 and once DF4&#8230;</p>
<p>Which brings me to another point, which not necessarily negative, but the TLF does introduce new terminology and knowledge. WTF is DF3 or DF4 or embedCFF. So now your Flash baggage has to be bigger, what about when Molehill comes out, we will have to be interface experts, typography experts and 3D experts???</p>
<p>Well I promise next article will be positive.</p>
 <p><a href="http://www.zedia.net/?flattrss_redirect&amp;id=775&amp;md5=95217e187f1a757ac7520b9149e4c0aa" 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/2011/new-text-layout-framework-same-font-problems/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sending byteArray (image) and variables to server-side script as POST data in AS3</title>
		<link>http://www.zedia.net/2010/sending-bytearray-image-and-variables-to-server-side-script-as-post-data-in-as3/</link>
		<comments>http://www.zedia.net/2010/sending-bytearray-image-and-variables-to-server-side-script-as-post-data-in-as3/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 17:07:49 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[2007]]></category>
		<category><![CDATA[as3corelib]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Jonathan Marston]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[server-side]]></category>
		<category><![CDATA[UploadPostHelper]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=687</guid>
		<description><![CDATA[A couple things here, I first talked about how to send an image and variables to the server (at the same time) on this post, but it felt a bit weird, the file had no name to retrieve it and the variables were sent as GET. Now while working a with a new colleague, he showed [...]]]></description>
			<content:encoded><![CDATA[<p>A couple things here, I first talked about how to send an image and variables to the server (at the same time) <a title="Sending byteArray and variables to server-side script at the same time" href="http://www.zedia.net/2008/sending-bytearray-and-variables-to-server-side-script-at-the-same-time/" target="_blank">on this post</a>, but it felt a bit weird, the file had no name to retrieve it and the variables were sent as GET. Now while working a with a new colleague, he showed me this code that for him was nothing but for me was amazing. It is a little library called UploadPostHelper made by <a title="Jonathan Marston" href="http://marstonstudio.com/" target="_blank">Jonathan Marston</a> back in 2007 (2007! why didn&#8217;t someone talk to me about this library before!!!).</p>
<p>Anyway here is a little code snippet showing how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> jpegEncoder:JPGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPGEncoder<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//using the JPGEncoder from as3corelib</span>
<span style="color: #000000; font-weight: bold;">var</span> jpegBytes:ByteArray = jpegEncoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>myPicture.<span style="color: #006600;">bitmapData</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//encoding a Bitmap into a ByteArray</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> urlRequest : URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
urlRequest.<span style="color: #0066CC;">url</span> = <span style="color: #ff0000;">&quot;THE URL OF YOUR SERVER SIDE SCRIPT&quot;</span>;
urlRequest.<span style="color: #0066CC;">contentType</span> = <span style="color: #ff0000;">'multipart/form-data; boundary='</span> + UploadPostHelper.<span style="color: #006600;">getBoundary</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
urlRequest.<span style="color: #006600;">method</span> = URLRequestMethod.<span style="color: #006600;">POST</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//now create an object with the variables you want to send as POST</span>
<span style="color: #000000; font-weight: bold;">var</span> postVariables:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>variable1Name:variable1Data, variable21Name:variable2Data, variable3Name:variable3Data<span style="color: #66cc66;">&#125;</span>
urlRequest.<span style="color: #0066CC;">data</span> = UploadPostHelper.<span style="color: #006600;">getPostData</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'image.jpg'</span>, jpegBytes,<span style="color: #ff0000;">&quot;filedata&quot;</span>, postVariables<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//here is where the magic happens, filedata will be the name to retrieve the file</span>
urlRequest.<span style="color: #006600;">requestHeaders</span>.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> URLRequestHeader<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'Cache-Control'</span>, <span style="color: #ff0000;">'no-cache'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//from here it is just a normal URLLoader</span>
_pictureUploader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
_pictureUploader.<span style="color: #006600;">dataFormat</span> = URLLoaderDataFormat.<span style="color: #006600;">BINARY</span>;
_pictureUploader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">COMPLETE</span>, _onUploadComplete, <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>;
_pictureUploader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span> urlRequest <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>How easy and beautiful is that?</p>
<p>So can get the code for the UploadPostHelper at the bottom of <a title="UploadPostHelper" href="http://marstonstudio.com/2007/10/19/how-to-take-a-snapshot-of-a-flash-movie-and-automatically-upload-the-jpg-to-a-server-in-three-easy-steps/" target="_blank">this post</a> or I have made a zip file with the <a title="UploadPostHelper" href="http://www.zedia.net/files/UploadPostHelper.zip" target="_blank">.as file here</a>.</p>
<p>Dude, 2007!</p>
 <p><a href="http://www.zedia.net/?flattrss_redirect&amp;id=687&amp;md5=40613c83d6397a471535f247ebaaa1aa" 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/sending-bytearray-image-and-variables-to-server-side-script-as-post-data-in-as3/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<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>
		<item>
		<title>Starting out with Alchemy (on a Mac)</title>
		<link>http://www.zedia.net/2010/starting-out-with-alchemy-on-a-mac/</link>
		<comments>http://www.zedia.net/2010/starting-out-with-alchemy-on-a-mac/#comments</comments>
		<pubDate>Fri, 14 May 2010 03:39:01 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Adobe Labs]]></category>
		<category><![CDATA[Alchemy]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[pico]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[zaalabs]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=614</guid>
		<description><![CDATA[So I&#8217;m a PC that now works on a Mac. It&#8217;s not my choice, but I went along with it to experience the Mac side of things. I don&#8217;t hate it, but I don&#8217;t like it that much either. That being said, it means that I am a complete noob user. For the past 2 [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m a PC that now works on a Mac. It&#8217;s not my choice, but I went along with it to experience the Mac side of things. I don&#8217;t hate it, but I don&#8217;t like it that much either. That being said, it means that I am a complete noob user. For the past 2 days, I have been trying to make Alchemy work (compiler that let&#8217;s you compile C and C++ libraries to a SWC that can be used in Flash) and it wasn&#8217;t all that easy.</p>
<p>First I&#8217;m going to point you to two articles on how to setup Alchemy. The first one can be found on Adobe Labs and has a <a title="Adobe labs steps for Alchemy" href="http://labs.adobe.com/wiki/index.php/Alchemy:Documentation:Getting_Started" target="_blank">detailed list of steps to complete in order to make Alchemy works</a>. The second one is <a title="zaalabs on compiling with alchemy" href="http://www.zaalabs.com/2010/04/compiling-with-alchemy-1/" target="_blank">from zaalabs</a> and it gives further information to get it done.</p>
<p>Now, even with those articles I had a lot of trouble to get it to work, mostly because I don&#8217;t know a lot about command line stuff. The first thing that confused me was the mention of a bash / shell / terminal interchangeably. Now, I know there is a difference between all of those, but in this case they all mean the terminal. You can access the terminal by going to Applications and inside the Utilities folder you&#8217;ll find the terminal.</p>
<p>The second thing that I didn&#8217;t understand was how to add something to the system path. This is also referred later on as adding to your paths. This means editing a file that will put a certain path to be handled like a system path so that you can access whatever is in that folder from any directory. To do so you have to edit a certain file named .profile. The problem that I had was that looking around the interweb for adding to the system path I found that I had to edit a file named .bash_profile. Well it turns out that both works but you just need one of those, if you put some info in one and some info in the other, just one of the file is going to be used so it won&#8217;t work. Just use .profile as mentioned in <a title="Adobe Labs steps for Alchemy" href="http://labs.adobe.com/wiki/index.php/Alchemy:Documentation:Getting_Started" target="_blank">Adobe doc</a>. Now that file is a hidden file (it starts with a &#8220;.&#8221;) and to see if it exist, in terminal, you must, right after you open it, write &#8220;ls -a&#8221;, the -a option will show you file that starts with a &#8220;.&#8221;. If the file .profile doesn&#8217;t exist you can create it using an editor like pico by writing &#8220;pico .profile&#8221;, writing what you need in it and saving the file. Just to help out, here is what my .profile file looks like after I have completed all the steps:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">source <span style="color: #66cc66;">/</span>Users<span style="color: #66cc66;">/</span>dominicg<span style="color: #66cc66;">/</span>library<span style="color: #66cc66;">/</span>Alchemy<span style="color: #66cc66;">/</span>alchemy-setup
PATH=$PATH:<span style="color: #66cc66;">/</span>Users<span style="color: #66cc66;">/</span>dominicg<span style="color: #66cc66;">/</span>Flex3<span style="color: #66cc66;">/</span>bin:<span style="color: #66cc66;">/</span>Users<span style="color: #66cc66;">/</span>dominicg<span style="color: #66cc66;">/</span>library<span style="color: #66cc66;">/</span>Alchemy<span style="color: #66cc66;">/</span>achacks
export PATH</pre></div></div>

<p>Last note to be sure everything works, you need to use the Flex SDK 3.2 and no other version. That <a title="Flex SDK 3.2" href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3" target="_blank">particular SDK can be found here.</a></p>
<p>Well I hope this will help some of you. I pretty much shifted focus from Alchemy since I started writing this article, but I am sure I will get back to it at some point.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/starting-out-with-alchemy-on-a-mac/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create your own ColorPicker using a Bitmap</title>
		<link>http://www.zedia.net/2010/create-your-own-colorpicker-using-a-bitmap/</link>
		<comments>http://www.zedia.net/2010/create-your-own-colorpicker-using-a-bitmap/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 02:59:52 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[ColorPicker]]></category>
		<category><![CDATA[getPixel]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=601</guid>
		<description><![CDATA[A while ago I did an application that required a colorpicker, I didn&#8217;t know much at the time so I chose to use the ColorPicker component that came with Flash CS3. That component is ok but it kinda is limited. After a little while I wanted more than what it was providing me.  I wanted [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I did an application that required a colorpicker, I didn&#8217;t know much at the time so I chose to use the ColorPicker component that came with Flash CS3. That component is ok but it kinda is limited. After a little while I wanted more than what it was providing me.  I wanted to imitate a bit the colorpicker that you can find in Photoshop. It turns out that it is pretty easy to do so. All you need is a picture of a color gamut and you are all set.</p>
<div id="attachment_603" class="wp-caption aligncenter" style="width: 257px"><a href="http://www.zedia.net/wp-content/uploads/2010/04/ColorPickerCS3.jpg"><img class="size-full wp-image-603" title="ColorPickerCS3" src="http://www.zedia.net/wp-content/uploads/2010/04/ColorPickerCS3.jpg" alt="" width="247" height="184" /></a><p class="wp-caption-text">ColorPicker component in Flash CS3</p></div>
<p>What we are going to do in short is transform this image of a color spectrum (bitmap) into a Sprite and when the mouse is over that Sprite, get the color that is right under the mouse. For the image of the color spectrum i&#8217;ll use a picture I found on <a title="color spectrum" href="http://en.wikipedia.org/wiki/List_of_palettes" target="_blank">wikipedia</a> and just resize it a bit. All you need is a picture with enough color on it, you could also use a picture of your dog if you wanted but the goal is more a picture with some organisation in the color.</p>
<p>Here is the picture I used:</p>
<div id="attachment_602" class="wp-caption aligncenter" style="width: 526px"><a href="http://www.zedia.net/wp-content/uploads/2010/04/colorPicker.jpg"><img class="size-full wp-image-602" title="Color Picker" src="http://www.zedia.net/wp-content/uploads/2010/04/colorPicker.jpg" alt="" width="516" height="132" /></a><p class="wp-caption-text">Color Spectrum for a ColorPicker</p></div>
<p>Now all you need to do is add a little bit of code to it and you have the basis of a color picker. The method that will do most of the work for us is a method from BitmapData called getPixel. You basically tell that method which pixel in the Bitmap, by providing it&#8217;s x and y coordinates, and getPixel will return you the color of that pixel. Now, this method returns the color as a unsigned integer that is not so legible, so we will have to convert that to an hexadecimal base so that we can relate to it.</p>
<p>But to be able to use this method (getPixel) we will need a BitmapData of the spectrum. In Flash, you can turn most MoviClip into BitmapData by using the method draw. I&#8217;ll do it in the following code snippet.</p>
<p>Here we go:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//Add the mouse funcitonality to the color picker</span>
myColorPicker.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">ROLL_OVER</span>, <span style="color: #0066CC;">onRollOver</span>, <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>;
myColorPicker.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">ROLL_OUT</span>, <span style="color: #0066CC;">onRollOut</span>, <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>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> myBitmapData:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>myColorPicker.<span style="color: #0066CC;">width</span>, myColorPicker.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
myBitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>myColorPicker<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onRollOver</span><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>
	myColorPicker.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, <span style="color: #0066CC;">onMouseMove</span>, <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: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onRollOut</span><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>
	myColorPicker.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, <span style="color: #0066CC;">onMouseMove</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onMouseMove</span><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>
	<span style="color: #000000; font-weight: bold;">var</span> myColor:uint = myBitmapData.<span style="color: #006600;">getPixel</span><span style="color: #66cc66;">&#40;</span>myColorPicker.<span style="color: #006600;">mouseX</span>, myColorPicker.<span style="color: #006600;">mouseY</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">trace</span> <span style="color: #66cc66;">&#40;</span>myColor.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//The toString(16) convert the uint into a legible hexadecimal representation ike in Photoshop</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<div>Now you have it, this is just the basis, but with that you can build a full fledged color picker.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/create-your-own-colorpicker-using-a-bitmap/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

