package
{
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
public class Main extends Sprite
{
private var _loader : Loader;
private var _player : Object;
public function Main()
{
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.INIT, _onLoaderInit, false, 0, true);
_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
}
private function _onLoaderInit(event : Event) : void
{
_player = _loader.content;
_player.addEventListener("onReady", _onPlayerReady, false, 0, true);
addChild(DisplayObject(_player));
_loader.contentLoaderInfo.removeEventListener(Event.INIT, _onLoaderInit);
_loader = null;
}
private function _onPlayerReady(event : Event) : void
{
_player.removeEventListener("onReady", _onPlayerReady);
// Once this event has been dispatched by the player, we can use
// cueVideoById, loadVideoById, cueVideoByUrl and loadVideoByUrl
// to load a particular YouTube video.
_player.setSize(640, 360);
_player.loadVideoById("D2gqThOfHu4");
}
}
}
если вы хотите использовать элементы управления YouTube, вам нужно будет заменить только одну строку:
//_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
//replace this line with the following
_loader.load(new URLRequest("http://www.youtube.com/v/VIDEO_ID?version=3"));
//replace VIDEO_ID with the id of the video you want to load in the previous case :"D2gqThOfHu4"
//also you can comment the following line if you don't want the video to start automatically:
_player.loadVideoById("D2gqThOfHu4");