Based on comments received in my previous article I’ve decided to also produce an example using Flash Professional CS4. The approach is different in some ways, but very similar in others.
View the Example:
[SWF]https://inflagrantedelicto.memoryspiral.com/wp-content/uploads/2009/10/YouTubeAS3_CS4.swf, 480, 500[/SWF]
References:
The ActionScript 3 YouTube Chromeless Player is Now Live
YouTube ActionScript 3.0 Player API Reference
Download the Example:
YouTubeAS3_CS4.zip
View Code for Flash Professional:
package {
import flash.system.Security;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
import fl.data.DataProvider;
import fl.controls.ComboBox;
import fl.controls.TextArea;
public class YouTubeAS3 extends MovieClip {
public var VidHolder:MovieClip;
public var VidSelection:ComboBox;
public var traceArea:TextArea;
private var player:Object;
private var loader:Loader;
private var vidCollection:DataProvider;
public function YouTubeAS3():void {
Security.allowInsecureDomain("*");
Security.allowDomain("*");
vidCollection = new DataProvider();
vidCollection.addItem({data:"KhAplw0Z8zQ", label:"Wreckage"});
vidCollection.addItem({data:"d54AA2YWll0", label:"Window View"});
vidCollection.addItem({data:"Sv83GeuyN8A", label:"The Fearless Man"});
vidCollection.addItem({data:"9t5guYGbuZs", label:"Ephemeral"});
VidSelection.dataProvider = vidCollection;
VidSelection.addEventListener(Event.CHANGE, cueVideo);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
}
private function onLoaderInit(event:Event):void {
VidHolder.addChild(loader);
loader.content.addEventListener("onReady", onPlayerReady);
loader.content.addEventListener("onError", onPlayerError);
loader.content.addEventListener("onStateChange", onPlayerStateChange);
loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);
}
private function onPlayerReady(event:Event):void {
traceArea.text += "player ready:" + Object(event).data + "\r";
player = loader.content;
player.setSize(VidHolder.width, VidHolder.height);
VidSelection.selectedIndex = 0;
VidSelection.dispatchEvent(new Event(Event.CHANGE));
}
private function cueVideo(event:Event):void {
traceArea.text += "switch to:" + event.target.selectedItem.label + "\r";
player.cueVideoById(event.target.selectedItem.data);
}
private function onPlayerError(event:Event):void {
traceArea.text += "player error:" + Object(event).data + "\r";
}
private function onPlayerStateChange(event:Event):void {
traceArea.text += "player state:" + Object(event).data + "\r";
}
private function onVideoPlaybackQualityChange(event:Event):void {
traceArea.text += "video quality:" + Object(event).data + "\r";
}
}
}
Pingback: Twitted by kevglx
Pingback: Squidoo Lens Tutorial ~ Reviews and a Video | Beginner’s Internet … « Wilson's Blog
Pingback: The new YouTube AS3 Chromeless API and Flex, Air, Flash | der hess
Hi Jospeh,
thanks for your tutorial. Sometimes it is a little bit ugly to work with the You Tube Chromeless API. I like to have some type-safed objects and code-completion. That was the reason why I created some easy to use classes for Flash, Flex and Air.
http://blog.derhess.de/2009/10/27/the-new-youtube-as3-chromeless-api-in-flex-air-flash/
Maybe it is interesting for you and your readers?!
Best regards,
Flo
Thanks for this example, been looking for something so simple and all the others I have found were going into the api. Nice. Thanks.
I can’t seem to get this to work. keep getting the error Load Never Completed. ????
Perhaps YouTube was down? Do you mean the embedded example isn’t working or that your implementation is not?
Hi, Joseph.
I can’t make it work even right here in your blog. Its trace field writes player error: 0. Both in FF and IE.
And could you upload a CS3 example? I cant open it in my CS3 flash.
I can’t make thise code work in FlashCS3.
Type was not found on these:
public var VidSelection:ComboBox;
public var traceArea:TextArea;
private var vidCollection:DataProvider;
and Definition could not be found on:
import fl.data.DataProvider;
import fl.controls.ComboBox;
import fl.controls.TextArea;
Would be nice if somebody can help. thanks, Steven
I think most of the components were rewritten for CS4. This is just example code- you’d have to use whatever components you have available.
This tutorial was helpful for my project! thanks a lot!
Hi,
I am using a similar script but without the dropdown menu.
I am getting ‘Security Sandbox Violation’ errors, I am using the following code, any help would be much apreciated?
// start
Security.allowDomain(“www.youtube.com”);
var my_player:Object;
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest(“http://www.youtube.com/v/CtOj8kpLIlI?version=3”));
my_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
function onLoaderInit(e:Event):void{
movArticles.movArticle2.videoPlayerHolder.videoMov2.addChild(my_loader);
my_player = my_loader.content;
my_player.addEventListener(“onReady”, onPlayerReady);
}
function onPlayerReady(e:Event):void{
my_player.setSize(640,360);
my_player.cueVideoById(“CtOj8kpLIlI”,0);
}
// end
just figured it out
added
Security.allowDomain(“s.ytimg.com”);