<?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>Wed, 21 Jul 2010 17:07:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>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>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fsending-bytearray-image-and-variables-to-server-side-script-as-post-data-in-as3%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/sending-bytearray-image-and-variables-to-server-side-script-as-post-data-in-as3/feed/</wfw:commentRss>
		<slash:comments>3</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>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fdrawing-bezier-tool-using-robotlegs%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/drawing-bezier-tool-using-robotlegs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>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>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fstarting-out-with-alchemy-on-a-mac%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/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>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fcreate-your-own-colorpicker-using-a-bitmap%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/create-your-own-colorpicker-using-a-bitmap/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Event bubbling in the ActionScript world</title>
		<link>http://www.zedia.net/2010/event-bubbling-in-the-actionscript-world/</link>
		<comments>http://www.zedia.net/2010/event-bubbling-in-the-actionscript-world/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 19:47:25 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Aviary]]></category>
		<category><![CDATA[bubble]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[event model]]></category>
		<category><![CDATA[Photoshop]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=593</guid>
		<description><![CDATA[I have been putting off writing this post but now that I am in between jobs I thought it was the good time. Well, I have been putting this off because it seemed like a good topic at the time, but eventually the concept of event bubbling became easy to me and than I felt [...]]]></description>
			<content:encoded><![CDATA[<p>I have been putting off writing this post but now that I am in between jobs I thought it was the good time. Well, I have been putting this off because it seemed like a good topic at the time, but eventually the concept of event bubbling became easy to me and than I felt no point in writing about it, but I guess it is not the same for every one. So here is my take on the subject.</p>
<h3>Event bubbling in general</h3>
<p>Event bubbling is not a concept that is particular to ActionScript but it is handled in special way by it. Event bubbling inscribe itself in an event model where events are dispatched and listened for. The bubbling part refers to event going up like bubbles in water (that&#8217;s my interpretation of the name). It doesn&#8217;t really make an sense also outside of the object oriented programming realm because of the need of encapsulation. It also implies some sort of composition because an object(Class (i&#8217;ll refer to #1 later)) needs to have another object(#2) created inside of it in order for it(#1) to listen to events dispatched by the second object(#2). Thus creating a hierarchy and enabling the possibility of event bubbling.</p>
<p>So in the preceding example I had 2 levels of hierarchy and every thing was fine, no need for event bubbling when object(#1) can easily listen to objects(#2) events. Now if I had 3 levels of hierarchy, object(#3) is inside of object(#2) which is inside of object(#1) we could use event bubbling to save some coding. Object(#1) can listen to object(#2) and object(#2) can listen to object(#3) but without adding code or making object(#3) public inside object(#2), object(#1) cannot receive the events from object(#3). Oh my, I hope this doesn&#8217;t sound too complicated with all those number signs. Ok so here we get to the concept, if we enabled the bubbling of events when dispatched in object(#3), the events would the go up (bubble) the hierarchy and make there way to object(#1) through object(#2) as if object(#2) had dispatched them. Keep on reading it gets easier (I hope).</p>
<h3>Event bubbling in ActionScript</h3>
<p>Now in the ActionScript world, event bubbling works in a particular way; it is tied to the Display List (<a title="Display List" href="http://www.flashandmath.com/intermediate/children/list.html" target="_blank">The &#8220;Display List&#8221; is the hierarchy of graphical objects in your movie to be displayed   on screen at runtime</a>) . Meaning you cannot have event bubbling, using the event system of ActionScript, if your dispatcher is not added to the Display List (you didn&#8217;t do addChild to a children of the Stage to add your object). You can dispatch events just fine, but they won&#8217;t bubble even if you set bubbling to true.</p>
<p>What is cool with the Diplay List is that you can really picture the hierarchy using the mathematical structure of the tree (well if you flip it upside down it looks like a tree). Here is an visual example.</p>
<p><a href="http://www.zedia.net/wp-content/uploads/2010/04/DisplayList.jpg"><img class="aligncenter size-full wp-image-594" title="DisplayList" src="http://www.zedia.net/wp-content/uploads/2010/04/DisplayList.jpg" alt="" width="625" height="465" /></a>Ok, not my best drawing, but I don&#8217;t have Photoshop right now; I used <a title="Aviary" href="http://aviary.com/" target="_blank">Aviary</a> for the first time and I can say it is quite nice to try, not Photoshop but I think you have to get used to it in order to see its full potential.</p>
<p>Now in that picture, if DisplayObject6 was to dispatch an event with bubbling to true here is who could listen to it.</p>
<ul>
<li>DisplayObjectContainer5 could listen to it; it is the direct parent of DisplayObject6, no need for event bubbling here</li>
<li>DisplayObjectContainer3 could listen to it by adding a listener on DisplayObjectContainer5</li>
<li>DisplayObjectContainer1 could listen to it by adding a listener on DisplayObjectContainer3</li>
<li>The Stage (or Main class) could listen to it by adding a listener on DisplayObject1</li>
</ul>
<p>Every body in the chain up from that object could listen to it (all at the same time if you wanted, doing each their different action upon receiving the event). If at some point you would like to stop the bubbling of the event you can always do so by using the stopPropagation method in the event class in your event handler method.</p>
<p>So as you see event bubbling is not a really hard concept and can save you from writing some boring repetitive code. (event handler methods). Anyway I might revisit this post later on to fix some things because I don&#8217;t think I was clear enough. Maybe I&#8217;ll had some code.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fevent-bubbling-in-the-actionscript-world%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/event-bubbling-in-the-actionscript-world/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using the ActionScript 3 YouTube Api</title>
		<link>http://www.zedia.net/2010/using-the-actionscript-3-youtube-api/</link>
		<comments>http://www.zedia.net/2010/using-the-actionscript-3-youtube-api/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 20:33:37 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[HD]]></category>
		<category><![CDATA[TubeLoc]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[YouTube]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=572</guid>
		<description><![CDATA[On October 14th YouTube released a new version of it&#8217;s API for Flash. This version would support ActionScript 3. Previously discussed on here was the library TubeLoc which was basically an AS3 wrapper around the ActionScript 2 API. Now the new API does all TubeLoc pertmitted us to do and even more. Well loading a [...]]]></description>
			<content:encoded><![CDATA[<p>On October 14th YouTube released a new version of it&#8217;s API for Flash. This version would support ActionScript 3. Previously discussed on <a href="http://www.zedia.net/2009/how-to-load-a-youtube-movie-into-flash-using-tubeloc/" target="_self">here was the library TubeLoc</a> which was basically an AS3 wrapper around the ActionScript 2 API. Now the new API does all TubeLoc pertmitted us to do and even more.</p>
<p>Well loading a YouTube video in ActionScript 3 has never been easier and there is nothing to download (which has its downside in some way)to get started.</p>
<p>Here is all the code needed to load a YouTube movie:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
 <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;
 <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Loader</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;">Event</span>;
 <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
&nbsp;
 <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <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> _loader : Loader;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _player : <span style="color: #0066CC;">Object</span>;
&nbsp;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> 
  _loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  _loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">INIT</span>, _onLoaderInit, <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>;
  _loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.youtube.com/apiplayer?version=3&quot;</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> _onLoaderInit<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>
  _player = _loader.<span style="color: #006600;">content</span>; 
  _player.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;onReady&quot;</span>, _onPlayerReady, <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>DisplayObject<span style="color: #66cc66;">&#40;</span>_player<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  _loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">INIT</span>, _onLoaderInit<span style="color: #66cc66;">&#41;</span>;
  _loader = <span style="color: #000000; font-weight: bold;">null</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onPlayerReady<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>
  _player.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;onReady&quot;</span>, _onPlayerReady<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #808080; font-style: italic;">// Once this event has been dispatched by the player, we can use</span>
  <span style="color: #808080; font-style: italic;">// cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl</span>
  <span style="color: #808080; font-style: italic;">// to load a particular YouTube video.  </span>
  _player.<span style="color: #006600;">setSize</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">640</span>, <span style="color: #cc66cc;">360</span><span style="color: #66cc66;">&#41;</span>;
  _player.<span style="color: #006600;">loadVideoById</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;D2gqThOfHu4&quot;</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>You can compile this code as an ActionScript project or make it the Document class of an fla in the Flash IDE to make it work.</p>
<p>So you start by loading the player using a normal Loader. Once the player is loaded you have to wait for it to send the onReady event before you can interact with it. Once this is done you can call all of the function from the API.</p>
<p>The previous code would load the chromeless YouTube player; but if you wanted to use the controls from YouTube you would only have to replace one line:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//_loader.load(new URLRequest(&quot;http://www.youtube.com/apiplayer?version=3&quot;));//replace this line with the following</span>
_loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.youtube.com/v/VIDEO_ID?version=3&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//replace VIDEO_ID with the id of the video you want to load in the previous case :&quot;D2gqThOfHu4&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//also you can comment the following line if you don't want the video to start automatically:</span>
_player.<span style="color: #006600;">loadVideoById</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;D2gqThOfHu4&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>All the functionalities that where accessible with TubeLoc are also accessible with the AS3 API and there are some more. Those are methods to control the quality setting of the loaded movie. You can set the quality to small, medium, large and hd720. To do so you have 3 methods on the player. getPlaybackQuality():String will return the quality of the video currently playing. setPlaybackQuality(suggestedQuality:String) enables you to set the quality. Finally, getAvailableQualityLevels():Array will return you all the possibilities of quality that you can set the current video to.</p>
<p>For more information on the topic, refer to the API : <a href="http://code.google.com/apis/youtube/flash_api_reference.html" target="_blank">http://code.google.com/apis/youtube/flash_api_reference.html</a></p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fusing-the-actionscript-3-youtube-api%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/using-the-actionscript-3-youtube-api/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Skinning the ComboBox Flash component</title>
		<link>http://www.zedia.net/2010/skinning-the-combobox-flash-component/</link>
		<comments>http://www.zedia.net/2010/skinning-the-combobox-flash-component/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 16:12:56 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[setRendererStyle]]></category>
		<category><![CDATA[Skinning]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=550</guid>
		<description><![CDATA[This post is more for me because I keep forgetting how to do this. For my defense I have to say that it is not exactly the first thing that comes to mind when you are trying to change the font in the ComboBox component, but at least I won&#8217;t have to remember in which [...]]]></description>
			<content:encoded><![CDATA[<p>This post is more for me because I keep forgetting how to do this. For my defense I have to say that it is not exactly the first thing that comes to mind when you are trying to change the font in the ComboBox component, but at least I won&#8217;t have to remember in which project I did it; I&#8217;ll just turn to my friend Google and type : comboBox + zedia.</p>
<p>Editing the visual is mostly easy inside of flash but my main problem is always the fonts. In a <a title="Fonts are my bane" href="http://www.zedia.net/2010/fonts-are-my-bane-not-anymore/" target="_self">previous post</a> I talked about fonts in Flash in general, this one will use that as a base and apply it to the ComboBox. Here is the code to change the font in the textfield and the dropping list:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myFormatWhite:<span style="color: #0066CC;">TextFormat</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextFormat</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
myFormatWhite.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;DFC GillSansLight&quot;</span>;
myFormatWhite.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">15</span>;
myFormatWhite.<span style="color: #0066CC;">color</span> = 0xffffff;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> myFormatBeige:<span style="color: #0066CC;">TextFormat</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextFormat</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
myFormatBeige.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;DFC GillSansLight&quot;</span>;
myFormatBeige.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">14</span>;
myFormatBeige.<span style="color: #0066CC;">color</span> = 0xa18c52;
&nbsp;
comboBox.<span style="color: #0066CC;">textField</span>.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;embedFonts&quot;</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
comboBox.<span style="color: #0066CC;">textField</span>.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;textFormat&quot;</span>, myFormatWhite<span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&amp;</span>lt;
&nbsp;
comboBox.<span style="color: #006600;">dropdown</span>.<span style="color: #006600;">setRendererStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;embedFonts&quot;</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
comboBox.<span style="color: #006600;">dropdown</span>.<span style="color: #006600;">setRendererStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;textFormat&quot;</span>, myFormatBeige<span style="color: #66cc66;">&#41;</span>;
&nbsp;
comboBox.<span style="color: #006600;">prompt</span> = <span style="color: #ff0000;">&quot;Province&quot;</span>; <span style="color: #808080; font-style: italic;">//default value that won't show in the dropdown</span>
comboBox.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">&quot;New Brunswick&quot;</span>, <span style="color: #0066CC;">data</span>:<span style="color: #ff0000;">&quot;New Brunswick&quot;</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;
comboBox.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">&quot;Nova Scotia&quot;</span>, <span style="color: #0066CC;">data</span>:<span style="color: #ff0000;">&quot;Nova Scotia&quot;</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;
comboBox.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">&quot;Ontario&quot;</span>, <span style="color: #0066CC;">data</span>:<span style="color: #ff0000;">&quot;Ontario&quot;</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;
comboBox.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">&quot;Prince Edward Island&quot;</span>, <span style="color: #0066CC;">data</span>:<span style="color: #ff0000;">&quot;Prince Edward Island&quot;</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>My problem was mostly with the setRendererStyle method; not that obvious. I also put the code for adding items in the ComboBox and to have a default text in it that doesn&#8217;t show in the dropdown. Now the next bit of code if to check, when you used ComboBox.prompt, if something was selected:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>comboBox.<span style="color: #006600;">selectedIndex</span> == -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #808080; font-style: italic;">//show error message because comboBox wasn't changed</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>P.S. all this code assumes that I have dragged the component to the stage in the Flash IDE</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fskinning-the-combobox-flash-component%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/skinning-the-combobox-flash-component/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>More on preloaders: passing the loaderInfo</title>
		<link>http://www.zedia.net/2010/more-on-preloaders-passing-the-loaderinfo/</link>
		<comments>http://www.zedia.net/2010/more-on-preloaders-passing-the-loaderinfo/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 03:48:40 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[FlashVars]]></category>
		<category><![CDATA[loaderInfo]]></category>
		<category><![CDATA[preloader]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=533</guid>
		<description><![CDATA[I previously made 2 posts on the topic of preloaders (The right way to do a preloader in AS3, External Preloader; more complex cases), well this post will be a continuation of those. And one that I believe not everyone will agree with me. I know that because I didn&#8217;t agree with it at first [...]]]></description>
			<content:encoded><![CDATA[<p>I previously made 2 posts on the topic of preloaders (<a title="Permanent Link to The right way to do a preloader in AS3" rel="bookmark" href="../2008/the-right-way-to-do-a-preloader-in-as3/">The right way to do a preloader in AS3,</a> <a title="Permanent Link to External Preloader; more complex cases" rel="bookmark" href="../2008/external-preloader-more-complex-cases/">External Preloader; more complex cases</a>), well this post will be a continuation of those. And one that I believe not everyone will agree with me. I know that because I didn&#8217;t agree with it at first but the more I thought about it the more it felt right.</p>
<p>When it comes to code I&#8217;m a bit of a fascist, I have trouble accepting habits of other coders if they are not the same as mine. So when I see something different my first reaction is to frown upon it (I am talking just about code; I am a very open minded person). When I first saw this mean of passing variables from the preloader to the main application that a coworker was doing I didn&#8217;t quite like it.</p>
<p>In the <a title="Permanent Link to External Preloader; more complex cases" rel="bookmark" href="../2008/external-preloader-more-complex-cases/">post about the more complex preloaders</a>, I showed how to use an interface to pass data from the preloader to the loaded (main) movie. Now this part of the code is still the same. What changes is that instead of passing the flashVars (variables that are passed to the flash from the html embed code or javascript) individually inside fo the init method of the Main class (also in the interface), we pass them all together by giving the root.loaderInfo instead.</p>
<p>I already know what you are going to say: this is not strictly typed so it is bad. I know, I know, but if you think about it a bit you see that at some point the flashVars are not typed anyway; when they transition from html to flash. So what is the harm of perpetuating this just one level more? In the init method inside the Main class, the first thing I do is that I type the parameters passed, so I do end up typing my variables.</p>
<p>Now, you&#8217;re going to ask what do you gain from this? Well, since the preloader is an external file, every time you are going to pass more variables to the Flash from the HTML, you will have to modify 3 files : the preloader.fla, the IMain.as and the Main.as. Now if you pass the loaderInfo instead of the individual flashVars, you will only need to modify the Main.as since it is there that you type the variables. You completely bypass the preloader, which in a way make sense since your preloader doesn&#8217;t need to know about your application, all it does is to load it. once your preloader is completed you don&#8217;t ever have to touch it again.</p>
<p>Here is some code to illustrate this. In the preloader :</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> mainContent:IMain;
<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onLoadComplete</span><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: #808080; font-style: italic;">// this would be the function that the loader would call when the loading is completed</span>
  mainContent = IMain<span style="color: #66cc66;">&#40;</span>loader.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>;
  addChild<span style="color: #66cc66;">&#40;</span>Sprite<span style="color: #66cc66;">&#40;</span>mainContent<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
  mainContent.<span style="color: #006600;">init</span><span style="color: #66cc66;">&#40;</span> root.<span style="color: #006600;">loaderInfo</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And in the Main class :</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package<span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">zedia</span>.<span style="color: #006600;">interfaces</span>.<span style="color: #006600;">IMain</span>;
  <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
  <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">display</span>.<span style="color: #006600;">LoaderInfo</span>;
 
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite <span style="color: #0066CC;">implements</span> IMain<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span>loaderInfo:LoaderInfo<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> flashVar1:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>loaderInfo.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">flashVar1</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #000000; font-weight: bold;">var</span> flashVar2:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#40;</span>loaderInfo.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">flashVar2</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #808080; font-style: italic;">//do something with the FlashVars</span>
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Fmore-on-preloaders-passing-the-loaderinfo%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/more-on-preloaders-passing-the-loaderinfo/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Fonts are my bane; not anymore!</title>
		<link>http://www.zedia.net/2010/fonts-are-my-bane-not-anymore/</link>
		<comments>http://www.zedia.net/2010/fonts-are-my-bane-not-anymore/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 15:15:07 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Embed]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[otf]]></category>
		<category><![CDATA[pfb]]></category>
		<category><![CDATA[ttf]]></category>
		<category><![CDATA[underline]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=521</guid>
		<description><![CDATA[I hate managing fonts in Flash, I truly hate it. I don&#8217;t understand why it is not easier than this after all that time. How about underline; why can&#8217;t we still underline in the Flash IDE? That shouldn&#8217;t be voodoo magic, even Notepad has underline, ok, Notepad doesn&#8217;t have the underlining functionality, but Wordpad does. [...]]]></description>
			<content:encoded><![CDATA[<p>I hate managing fonts in Flash, I truly hate it. I don&#8217;t understand why it is not easier than this after all that time. How about underline; why can&#8217;t we still underline in the Flash IDE? That shouldn&#8217;t be voodoo magic, even Notepad has underline, ok, Notepad doesn&#8217;t have the underlining functionality, but Wordpad does.</p>
<p>Anyway, my biggest problem with fonts and Flash is not the underlining problem, but when you start using static and dynamic textfields with the same font family but with different font style. When you do that, your dynamic textfields will just not show and that is really annoying. A solution that works is if you put all textfields dynamic, but that&#8217;s even more annoying.</p>
<p>Now a really cool feature is that you can now embed fonts using the embed tag just like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/fonts/GNL_____.PFB&quot;</span>, fontName =<span style="color: #ff0000;">&quot;zedia GillSansLight&quot;</span>, unicodeRange=<span style="color: #ff0000;">'U+0020-U+007A, U+00C0-U+00F6, U+2019'</span>, mimeType=<span style="color: #ff0000;">&quot;application/x-font-truetype&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> GillSansLight2:<span style="color: #000000; font-weight: bold;">Class</span>;</pre></div></div>

<p>Not sure that this will work when you compile using the Flash IDE, but when doing ActionScript projects or Flex projects this works just fine. This way you can embed ttf, otf and pfb fonts. I am not quite sure how to embed fonts on a Mac system, it will still work with those formats, but I know Macintosh has other formats. The thing that makes this work is that you can specify the font name. Be sure to specify a name that you know Flash wouldn&#8217;t specify. My coworker gave me the trick to add the name of the project in the font name that way it&#8217;s always going to be different than Flash. If you don&#8217;t make it different you will still run in the problem of your dynamic textfields not showing up.</p>
<p>Once you have embedded the font you need to register it in your application like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">Font</span>.<span style="color: #006600;">registerFont</span><span style="color: #66cc66;">&#40;</span>GillSansLight2<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This will make the font available anywhere in your application. All you need to do is create a TextFormat with that font and assign that TextFormat to your textfield:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> tf:<span style="color: #0066CC;">TextFormat</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextFormat</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;zedia GillSansLight&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//this is what you put into fontName in the embed tag</span>
myTextfield.<span style="color: #0066CC;">embedFonts</span> = <span style="color: #000000; font-weight: bold;">true</span>; <span style="color: #808080; font-style: italic;">//this line is also important</span>
myTextfield.<span style="color: #006600;">defaultTextFormat</span> = tf; <span style="color: #808080; font-style: italic;">//always assign the default textformat before modifying the text property</span>
myTextfiled.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;lorem ipsum&quot;</span>;</pre></div></div>

<p>Now, using this technique you can choose exactly what character from the font you want to embed. In the previous example the unicodeRange represented those characters:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">U+0020-U+007A = <span style="color: #0066CC;">SPACE</span><span style="color: #66cc66;">!</span><span style="color: #ff0000;">&quot;#$%&amp;amp;'()*+,-./0123456789:;&amp;lt;=&amp;gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[<span style="color: #000099; font-weight: bold;">\]</span>^_`abcdefghijklmnopqrstuvwxyz
U+00C0-U+00F6 = ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö
U+2019 = ’</span></pre></div></div>

<p>This is a pretty safe set, but you can always change it and optimize it.</p>
<p>Here is a good resource to do Unicode conversion:<br />
<a title="Unicode converter" href="http://rishida.net/scripts/uniview/conversion.php" target="_blank">http://rishida.net/scripts/uniview/conversion.php</a></p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2010%2Ffonts-are-my-bane-not-anymore%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2010/fonts-are-my-bane-not-anymore/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to load a YouTube movie into Flash using TubeLoc</title>
		<link>http://www.zedia.net/2009/how-to-load-a-youtube-movie-into-flash-using-tubeloc/</link>
		<comments>http://www.zedia.net/2009/how-to-load-a-youtube-movie-into-flash-using-tubeloc/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 17:04:07 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[FFDMag]]></category>
		<category><![CDATA[TubeLoc]]></category>
		<category><![CDATA[Video Player]]></category>
		<category><![CDATA[YouTube]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=491</guid>
		<description><![CDATA[I have written this article a while back for FFDMag, but I thought I would put it here also. It lost a bit of relevance because YouTube now has an AS3 API for its player, but if you work on a project that uses TubeLoc, I think this article can be useful. What you should [...]]]></description>
			<content:encoded><![CDATA[<p><em>I have written this article a while back for <a title="FFDMag" href="http://ffdmag.com/magazine/881-branding-for-developers" target="_blank">FFDMag</a>, but I thought I would put it here also. It lost a bit of relevance because YouTube now has an <a title="YouTube AS3 API" href="http://code.google.com/apis/youtube/flash_api_reference.html" target="_blank">AS3 API</a> for its player, but if you work on a project that uses TubeLoc, I think this article can be useful.</em></p>
<p><strong>What you should know:</strong><br />
- Basic knowledge of ActionScript<br />
- Basic knowledge of YouTube</p>
<p><strong>What you will learn:</strong><br />
- How to load YouTube videos into Flash<br />
- How to use the TubeLoc library to control those videos</p>
<p>Embedding a YouTube movie in an HTML page is an easy task, but we can&#8217;t say the same about embedding a YouTube clip in a Flash/Flex website. TubeLoc, an opensource library, is there to make that easier.</p>
<p>Before TubeLoc, you could always go and try to find the address of the FLV the YouTube player is loading and load that FLV directly into your Flash application, but YouTube changes the address almost every night, so it wasn&#8217;t a very long term solution. Another problem that TubeLoc solves is the fact that the YouTube player is made in ActionScript 2 and most projects now are using ActionScript 3, so it was hard interfacing with the player. TubeLoc is a wrapper around the the AS2 player and show us an AS3 API, but behind the scene it handles the YouTube player using local connection.</p>
<p>To get started with TubeLoc you will first need to download the library at this address:</p>
<p><a title="TubeLoc" href="http://code.google.com/p/tubeloc/" target="_blank">http://code.google.com/p/tubeloc/</a></p>
<p>There you will also find a great demo showing you what you can do with the library. You can pause, stop, play, mute, seek, change the volume, change the the size of the video and even load the video without the YouTube player chrome (so you won&#8217;t see the play button from YouTube the only thing that will be there is the YouTube logo at the bottom right of the video).</p>
<p>In the zip file that you download from the previous url, copy the &#8220;com&#8221; folder located in the &#8220;as3/src&#8221; folder in the same directory where your FLA will be. Also copy there the file as2_tubeloc.swf from the folder &#8220;as3/lib&#8221;. Now we can get coding. Here is all that is needed to load a YouTube movie into Flash:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> com.<span style="color: #006600;">enefekt</span>.<span style="color: #006600;">tubeloc</span>.<span style="color: #006600;">MovieSprite</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">enefekt</span>.<span style="color: #006600;">tubeloc</span>.<span style="color: #006600;">event</span>.<span style="color: #66cc66;">*</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> youtubeMovie:MovieSprite = <span style="color: #000000; font-weight: bold;">new</span> MovieSprite<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
youtubeMovie.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>PlayerReadyEvent.<span style="color: #006600;">PLAYER_READY</span>, onPlayerReady<span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span>youtubeMovie<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> onPlayerReady<span style="color: #66cc66;">&#40;</span>event_p:PlayerReadyEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #808080; font-style: italic;">//it's just cleaner to remove listener that won't be used again</span>
youtubeMovie.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>PlayerReadyEvent.<span style="color: #006600;">PLAYER_READY</span>, onPlayerReady<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//you can set the size of the movie this way</span>
youtubeMovie.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">370</span>;
youtubeMovie.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">276</span>;
&nbsp;
youtubeMovie.<span style="color: #006600;">loadVideoById</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;tprMEs-zfQA&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The first lines import the library from the &#8220;com&#8221; folder we copied. After that it creates the MovieSprite. The first parameter is the id of the YouTube movie, since I will set that later I can just pass null to it. The second parameter is if I want to use the chromeless player, in this case I set it to true. The chromeless player is usefull when you want the video player to have control that are similar to the rest of your application. It is also usefull when you want to put your video under a mask to escape the traditonnal square look of videos. If we continue with the code, after we created the MovieSprite, we have to wait for the player to be initialized to go on that&#8217;s why we put an event listener on the MovieSprite(youtubeMovie). Once the listener function is called, all that is left to do is call the loadVideoById method. Finding a video id from YouTube is really easy; if the url of the video you want to load looks like this:</p>
<p><a title="Youtube video" href="http://www.youtube.com/watch?v=tprMEs-zfQA">http://www.youtube.com/watch?v=tprMEs-zfQA</a></p>
<p>Than your id is only the last part : &#8220;tprMEs-zfQA&#8221;.</p>
<p>Now if you want to control your video all you have to do is :</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//this will pause the video</span>
youtubeMovie.<span style="color: #006600;">pauseVideo</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//this will make it play again</span>
youtubeMovie.<span style="color: #006600;">playVideo</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//to mute the video</span>
youtubeMovie.<span style="color: #006600;">mute</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//to set the volume to half of maximum</span>
youtubeMovie.<span style="color: #0066CC;">setVolume</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//to seek in the video to 20 seconds</span>
youtubeMovie.<span style="color: #006600;">seekTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Well that is all it take to load a YouTube movie into Flash. I should warn you of some pitfalls; by reading the issues on the google code page, there seems to be problems with loading multiple videos at the same time. Also, destroying an instance of a MovieSprite seems to inhibit you from creating another one after so you should always keep an instance of you MovieSprite alive. Aside from that TubeLoc is an awesome library and I hope to see the proliferation of YouTube videos inside of Flash!</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2009%2Fhow-to-load-a-youtube-movie-into-flash-using-tubeloc%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2009/how-to-load-a-youtube-movie-into-flash-using-tubeloc/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
