<?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; AS3</title>
	<atom:link href="http://www.zedia.net/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zedia.net</link>
	<description>Flash, ActionScript, SEO and everything in between</description>
	<lastBuildDate>Thu, 02 Feb 2012 17:58:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Donut Charts in AS3</title>
		<link>http://www.zedia.net/2011/donut-charts-in-as3/</link>
		<comments>http://www.zedia.net/2011/donut-charts-in-as3/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 14:24:20 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Charts]]></category>
		<category><![CDATA[Donut Chart]]></category>
		<category><![CDATA[Lee Brimeloww]]></category>
		<category><![CDATA[Pie Charts]]></category>

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

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

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

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

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

		<guid isPermaLink="false">http://www.zedia.net/?p=439</guid>
		<description><![CDATA[TimelineLite is a new library from the maker of TweenLite that enables you to group TweenLite instances (Tweens) to create the equivalent of the Flash Authoring Tool Timeline but in code. If you don&#8217;t know what TweenLite is head over to my tutorial on it first. What is it for The goal of this library [...]]]></description>
			<content:encoded><![CDATA[<p><a title="TimelineLite" href="http://blog.greensock.com/v11beta/" target="_blank">TimelineLite</a> is a new library from the maker of <a title="TweenLite" href="http://blog.greensock.com/tweenliteas3/" target="_blank">TweenLite</a> that enables you to group TweenLite instances (Tweens) to create the equivalent of the Flash Authoring Tool Timeline but in code. If you don&#8217;t know what TweenLite is head over to my <a title="TweenLite Tutorial Tween AS3" href="http://www.zedia.net/2008/actionscript-3-tweenlite-basic-tutorial/" target="_self">tutorial on it</a> first.</p>
<h3>What is it for</h3>
<p>The goal of this library is to give more power to the already powerful TweenLite library and to emulate some of the MovieClip&#8217;s functionalities. Once built, a TimelineLite instance will possess some methods that we&#8217;ve known for a long time: play(), stop(), gotoAndPlay(), etc. Three methods are used to create the timeline: append(), insert(), insertMultipple(). I prefer the insert method, it gives you more flexibility because you can set the time at which the Tween starts. The append() method will simply add your TweenLite instance at the end of the current timeline.</p>
<p>Here are some examples of how you would create a TimelineLite :</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myTimeline:TimelineLite = <span style="color: #000000; font-weight: bold;">new</span> TimelineLite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//this will have 3 tween starting one after the one before is done</span>
myTimeline.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>mc, <span style="color: #cc66cc;">1</span>, <span style="color: #66cc66;">&#123;</span>x:<span style="color: #cc66cc;">200</span>, y:<span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
myTimeline.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>alpha:<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
myTimeline.<span style="color: #006600;">append</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>alpha:<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
myTimeline.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//this one will have concurrent tweens a bit like layered tweens in the Flash Timeline</span>
myTimeline.<span style="color: #0066CC;">insert</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>mc, <span style="color: #cc66cc;">1</span>, <span style="color: #66cc66;">&#123;</span>x:<span style="color: #cc66cc;">200</span>, y:<span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
myTimeline.<span style="color: #0066CC;">insert</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>alpha:<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">0.75</span><span style="color: #66cc66;">&#41;</span>;
myTimeline.<span style="color: #0066CC;">insert</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>scaleX:<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1.25</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Some of the cool stuff you can do with is that inside a TimelineLite you can insert other TimelineLite instances. Also you can add Labels and tween using TweenLite to those labels. You can tween the time of the timeline as well as the progress. Here are examples of what I just mentioned:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myTimeline:TimelineLite = <span style="color: #000000; font-weight: bold;">new</span> TimelineLite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
myTimeline.<span style="color: #0066CC;">insert</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>mc, <span style="color: #cc66cc;">1</span>, <span style="color: #66cc66;">&#123;</span>x:<span style="color: #cc66cc;">200</span>, y:<span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
myTimeline.<span style="color: #0066CC;">insert</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>alpha:<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">0.75</span><span style="color: #66cc66;">&#41;</span>;
myTimeline.<span style="color: #0066CC;">insert</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TweenLite<span style="color: #66cc66;">&#40;</span>mc, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>scaleX:<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//Tween the timeline to any place in percent (from 0 to 1)</span>
TweenLite.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>myTimeline, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span>progress:<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//Tween to a particular second in time (from 0 to the duration of the timeline)</span>
TweenLite.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>myTimeline, <span style="color: #cc66cc;">0.5</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">time</span>:<span style="color: #cc66cc;">0.75</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h3>Its advantages</h3>
<p>The major advantage that TimelineLite posesses over real timeline is the fact that it is dynamic. Meaning that you could make an function that takes a display object, that function would create an animation based on it and return a TimelineLite instance that you could use afterward. Then you could use that function to create the same animation on multiple display objects. Another example is that you could create animation based on what the user does, like you make him choose a number and you append that many instances on TweenLite in your TimelineLite (easy to do with traditionnal timeline too, but its just an example).</p>
<h3>Its Max conterpart</h3>
<p>As for the TweenLite library, TimelineLite has its Max equivalent, TimelineMax, which has more features like AS3 event listeners, repeat, repeatDelay, yoyo, addCallback(), removeCallback(), getActive(), etc.  Just to tell you how good this library is,  I have done a TimelineLite instance that tweened 25 display objects and 625 TweenLite instances and it worked perfectly fine, it wasn&#8217;t even slowing down.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2009/introduction-to-timelinelite-timelinemax/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to connect to Google Analytics Data API in Flash</title>
		<link>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-flash/</link>
		<comments>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-flash/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 04:21:43 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[GData]]></category>
		<category><![CDATA[Google Analytics Data Api]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=424</guid>
		<description><![CDATA[In one of my previous post, I explained how to connect to Google Analytics Data API in AIR. The problem with that way of connecting was that it only worked in AIR. In Flash it works locally, but as soon as you put in on your web server it stops working. Not it is cool [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my previous post, I explained <a title="How to connect to Google Analytics Data API in AIR" href="http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-air/" target="_self">how to connect to Google Analytics Data API in AIR</a>. The problem with that way of connecting was that it only worked in AIR. In Flash it works locally, but as soon as you put in on your web server it stops working. Not it is cool to build an AIR (desktop) application that pulls data from Google Analytics, but it would also be cool to build a web application that does the same thing. Well I found out how to do just that. It is a bit more complicated because it involves a bit of server side coding, in this case PHP.</p>
<p>How the process works is that first you login to Google Analytics, Google will then send you a token that you must use when asking for data. So we will have two simple PHP files; one to login in and one to ask for data.</p>
<p>The first one looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//this file is called get_token.php</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span>user<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span>pass<span style="color: #009900;">&#93;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'curl.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$curl</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Curl<span style="color: #339933;">;</span>
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$curl</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>post<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https://www.google.com/accounts/ClientLogin'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>accountType <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;GOOGLE&quot;</span><span style="color: #339933;">,</span>  Email <span style="color: #339933;">=&gt;</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span> Passwd <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pass</span><span style="color: #339933;">,</span> service <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;analytics&quot;</span><span style="color: #339933;">,</span> source <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;zedia-GAStats-0&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tempArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Auth=&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;root&gt;
	&lt;token&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tempArray</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/token&gt;
&lt;/root&gt;</pre></div></div>

<p>The second one looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//this file is called call_ga.php</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'curl.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$token</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;token&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$curl2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #339933;">,</span> CURLOPT_HTTPHEADER<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Authorization: GoogleLogin auth='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$token</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$response2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$curl2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As you can see to make my calls to Google I am using the cURL library that is usually already installed on your server if you have PHP. Also for the get_token.php I am also using the <a title="Curl Class" href="http://github.com/shuber/curl/blob/ee9f201544f826ed909f7a149447cade6c92e587/curl.php" target="_blank">Curl class</a>, made by <a title="Sean Huber" href="http://huberry.com/blog" target="_blank">Sean Huber</a>, that just makes it easier to work with cURL.  Upload these files to your server. Now that we have the server side figured out, we can move on to the Flash part;  here it is:</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;">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;">URLLoader</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLVariables</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</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:URLLoader;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _loader2:URLLoader;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _textField:<span style="color: #0066CC;">TextField</span>;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _token:<span style="color: #0066CC;">String</span>;
  <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _buffer:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
  <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: #0066CC;">void</span>
  <span style="color: #66cc66;">&#123;</span>
    loader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    loader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, _onTokenLoaded, <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: #808080; font-style: italic;">//this call will load the token</span>
&nbsp;
    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.YOUR_URL_WHERE_THE_PHP_RESIDE.net/get_token.php?user=YOUR_USERNAME&amp;pass=YOUR_PASSWORD&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    _textField = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    _textField.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">300</span>;
    _textField.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">300</span>;
    _textField.<span style="color: #0066CC;">multiline</span> = <span style="color: #000000; font-weight: bold;">true</span>;
    _textField.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
    addChild<span style="color: #66cc66;">&#40;</span>_textField<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> _onTokenLoaded<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: #000000; font-weight: bold;">var</span> tempString:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>loader.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
    tempString = tempString.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, tempString.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> tempXML:<span style="color: #0066CC;">XML</span> = <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span>tempString<span style="color: #66cc66;">&#41;</span>;
    _token = tempXML.<span style="color: #006600;">token</span>;
&nbsp;
    _textField.<span style="color: #0066CC;">text</span> = _token;
&nbsp;
    _loader2 = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    _loader2.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, _onFeedLoaded, <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> request:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.YOUR_URL_WHERE_THE_PHP_RESIDE.net/call_ga.php&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> urlVar:URLVariables = <span style="color: #000000; font-weight: bold;">new</span> URLVariables<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    urlVar.<span style="color: #006600;">token</span> = _token;
    urlVar.<span style="color: #0066CC;">url</span> = <span style="color: #ff0000;">&quot;https://www.google.com/analytics/feeds/accounts/default&quot;</span>;
    request.<span style="color: #0066CC;">data</span> = urlVar;
&nbsp;
    _loader2.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>request<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> _onFeedLoaded<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>
    _textField.<span style="color: #0066CC;">text</span> = <span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#40;</span>_loader2.<span style="color: #0066CC;">data</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>What you basically do is that you use your server to do all the communication between the Flash and Google. Everytime you will want a different feed to get different data you will call the call_ga.php file. It is that simple. If you have any question on this feel free to ask them in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-flash/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How to connect to Google Analytics Data API in AIR</title>
		<link>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-air/</link>
		<comments>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-air/#comments</comments>
		<pubDate>Fri, 22 May 2009 03:37:38 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[as3corelib]]></category>
		<category><![CDATA[as3crypto]]></category>
		<category><![CDATA[as3httpclientlib]]></category>
		<category><![CDATA[GData]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Google Analytics Data Api]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=415</guid>
		<description><![CDATA[I had a bit of trouble doing just this a while ago, ended up trying many different ways and finally a reader of this blog, Nakamachi, gave me the solution. Because I think many of you are trying to connect to Google Analytics Data API ( or any Google APIs for that matters) I will [...]]]></description>
			<content:encoded><![CDATA[<p>I had a bit of trouble doing <a title="Connecting to Google Analytics Data Api using AS3; my failures" href="http://www.zedia.net/2009/connecting-to-google-analytics-data-api-using-as3-my-failures/" target="_self">just this a while ago</a>, ended up trying many different ways and finally a reader of this blog, <span class="info">Nakamachi, gave me the solution. Because I think many of you are trying to connect to Google Analytics Data API ( or any Google APIs for that matters) I will give you here my solution. My solution only works in AIR; I don&#8217;t know why, but as soon as I put it on the web, it stops working. I have found a solution for that problem too but I will keep it for another post.</span><br />
Here is how you can connect to GData:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">HttpClient</span>;
<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">net</span>.<span style="color: #006600;">URI</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">HttpResponseEvent</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">HttpRequestEvent</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">HttpRequest</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">http</span>.<span style="color: #0066CC;">Get</span>;
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">httpclient</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">HttpDataEvent</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> _firstBuffer:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
<span style="color: #000000; font-weight: bold;">var</span> _secondBuffer:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//this first connection will get the authorization token by sending the user name and password for Google Analytics</span>
<span style="color: #000000; font-weight: bold;">function</span> submitForm<span style="color: #66cc66;">&#40;</span>email:<span style="color: #0066CC;">String</span>, <span style="color: #0066CC;">password</span>:<span style="color: #0066CC;">String</span><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> client:HttpClient = <span style="color: #000000; font-weight: bold;">new</span> HttpClient<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> uri:URI = <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;https://www.google.com/accounts/ClientLogin&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> variables:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;accountType&quot;</span>, value:<span style="color: #ff0000;">&quot;GOOGLE&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;Email&quot;</span>, value: email<span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;Passwd&quot;</span>, value: <span style="color: #0066CC;">password</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;service&quot;</span>, value: <span style="color: #ff0000;">&quot;analytics&quot;</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">name</span>:<span style="color: #ff0000;">&quot;source&quot;</span>, value: <span style="color: #ff0000;">&quot;your-application-identifier&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span>;
  client.<span style="color: #006600;">listener</span>.<span style="color: #0066CC;">onData</span> = _onFirstData;
  client.<span style="color: #006600;">listener</span>.<span style="color: #006600;">onComplete</span> = _onLoaderComplete;
  client.<span style="color: #006600;">postFormData</span><span style="color: #66cc66;">&#40;</span>uri, variables<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> _onFirstData<span style="color: #66cc66;">&#40;</span>event:HttpDataEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  _firstBuffer += event.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//this second connection will request information to GData</span>
<span style="color: #808080; font-style: italic;">//in this case account info for Google Analytics by</span>
<span style="color: #808080; font-style: italic;">//putting the auth token in the header of the request</span>
<span style="color: #000000; font-weight: bold;">function</span> _onLoaderComplete<span style="color: #66cc66;">&#40;</span>event:HttpResponseEvent<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> tempArray:<span style="color: #0066CC;">Array</span> = _firstBuffer.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Auth=&quot;</span><span style="color: #66cc66;">&#41;</span>;
 <span style="color: #000000; font-weight: bold;">var</span>  _authToken:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span>tempArray<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #000000; font-weight: bold;">var</span> client:HttpClient = <span style="color: #000000; font-weight: bold;">new</span> HttpClient<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> uri:URI = <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;https://www.google.com/analytics/feeds/accounts/default&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">var</span> request:HttpRequest = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  request.<span style="color: #006600;">addHeader</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Authorization&quot;</span>, <span style="color: #ff0000;">&quot;GoogleLogin auth=&quot;</span> + _authToken<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  client.<span style="color: #006600;">listener</span>.<span style="color: #0066CC;">onData</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>event:HttpDataEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
    _secondBuffer += event.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
  client.<span style="color: #006600;">listener</span>.<span style="color: #006600;">onComplete</span> = _onSecondLoaderComplete;
  client.<span style="color: #006600;">request</span><span style="color: #66cc66;">&#40;</span>uri, request<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> _onSecondLoaderComplete<span style="color: #66cc66;">&#40;</span>event:HttpResponseEvent<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>_secondBuffer<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>As you can see in order to circumvent the Authorization header restriction I am using the <a title="as3httpclientlib" href="http://code.google.com/p/as3httpclientlib/">as3httpclientlib</a> library which requires the <a title="as3corelib" href="http://code.google.com/p/as3corelib/" target="_blank">as3corelib</a> and <a title="as3crypto" href="http://code.google.com/p/as3crypto/" target="_blank">as3crypto</a> libraries to compile. Using the same principle you should be able to connect to Google APIs from your AIR application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2009/how-to-connect-to-google-analytics-data-api-in-air/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

