YouTube的无铬AS3播放器 [英] youtube chromeless as3 player

查看:400
本文介绍了YouTube的无铬AS3播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我玩玩而已的新的YouTube AS3 API,但卡住了。这是 多远,我得到了(从看他们的样code)。

I'm goofing around with the new youtube as3 API but got stuck. This is how far i got (from looking at their sample code).

http://pastie.org/656088

public class Main extends Sprite 
{
    Security.allowDomain("*");

    private var player:Object;
    private var loader:Loader;

    public function Main():void 
    {
    	if (stage) init();
    	else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
    	removeEventListener(Event.ADDED_TO_STAGE, init);

    	loader = new Loader();
    	loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
    	loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
    }

    private function onLoaderInit(e:Event):void
    {
    	addChild(loader);
    	loader.contentLoaderInfo.addEventListener("onReady", onPlayerReady);
    	loader.contentLoaderInfo.addEventListener("onError", onPlayerError);
    	loader.contentLoaderInfo.addEventListener("onStateChange", onPlayerStateChange);
    	loader.contentLoaderInfo.addEventListener("onPlayerQualityChange", onVideoPlaybackQualityChange);
    }

    private function onPlayerReady(e:Event):void
    {
    	trace("Player ready: " + Object(e).Data);
    }
    private function onPlayerError(e:Event):void
    {
    	trace("Player error: " + Object(e).Data);
    }
    private function onPlayerStateChange(e:Event):void
    {
    	trace("Player state: " + Object(e).Data);
    }
    private function onVideoPlaybackQualityChange(e:Event):void
    {
    	trace("Video quality: " + Object(e).Data);
    }
}

我真的不知道是什么,下一步就是。我没有得到任何错误,并没有被跟踪。我是pretty的肯定,我的事件没有正确实施。

I don't really know what the next step is. I get no errors and nothing gets traced. I'm pretty sure that my events are not implemented correctly.

更新: 我跟着Amarghosh的回答,这样做,而不是:

Update: I followed Amarghosh's answered and did this instead:

private function onLoaderInit(e:Event):void
{
  player = Sprite(loader.content);
  addChild(player);
  player.addEventListener("onReady", onPlayerReady);
  player.addEventListener("onError", onPlayerError);
  player.addEventListener("onStateChange", onPlayerStateChange);
  player.addEventListener("onPlayerQualityChange", onVideoPlaybackQualityChange);
}

现在的onPlayerReady和onStateChange事件,火灾,但我得到的错误。当跟踪对象(E)。数据我得到这个错误

Now the onPlayerReady and the onStateChange events fires but i get errors. When tracing Object(e).Data i get this error

的ReferenceError:错误#1069:该属性的数据,未发现com.google.youtube.event.ExternalEvent并没有标准值 (瑞典stranslated) 当更改到对象(e.target)。数据它的踪迹不确定和对象(e.target)跟踪[对象SwfProxy]。

ReferenceError: Error #1069: the property Data was not found for com.google.youtube.event.ExternalEvent and there is no standard value. (stranslated from swedish) When changing to Object(e.target).Data it traces "undefined" and Object(e.target) traces [object SwfProxy].

如果我尝试 player.loadVideoById(uad17d5hR5s); 我得到这个错误:

If i try player.loadVideoById("uad17d5hR5s"); i get this error:

1061:雪碧

推荐答案

对不起,所有图书馆的困惑,我想我已经回答了你的其他错误,但。当你这样做雪碧(loader.content)你力投玩家是一个精灵,因为你想要的API的方法我会建议使用一个普通的旧对象,因为它不会抱怨无类型的方法:

sorry for all the library confusion, I think I have the answer to your other error though. When you do this Sprite(loader.content) you 'force' cast the player to be a sprite, because you want methods of the api I would recommend using a plain old object, because it won't complain about untyped methods:

// No particluar type
var player:Object;

private function onLoaderInit(e:Event):void
{
	player = loader.content;
	addChild(player as DisplayObject);

	var dispatcher:IEventDispatcher = player as IEventDispatcher;
	dispatcher.addEventListener("onReady", onPlayerReady);
	dispatcher.addEventListener("onError", onPlayerError);
	dispatcher.addEventListener("onStateChange", onPlayerStateChange);
	dispatcher.addEventListener("onPlayerQualityChange", onVideoPlaybackQualityChange);
}

这篇关于YouTube的无铬AS3播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆