<?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; HD</title>
	<atom:link href="http://www.zedia.net/tag/hd/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>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>
	</channel>
</rss>

